x 值对 y 的 Matplotlib 线图
Matplotlib line plot of x values against y
我有一个 x 值列表,我想在 y 轴上绘制(用线条)。
也就是说,如果 x = [3, 5, 2, 4] 且 y = ['A', 'B', 'C', 'D'],则情节可能看起来像这样(除非不是手绘):
恐怕我在 matplotlib.pyplot 文档 / SO / google 中没有看到任何指向正确方向的内容,甚至没有看到它的名称。有什么指点吗?
我想你在找这样的东西
import numpy as np
import matplotlib.pyplot as plt
fig,ax = plt.subplots(1)
# create some x data and some integers for the y axis
x = np.array([3,5,2,4])
y = np.arange(4)
# plot the data
ax.plot(x,y)
# tell matplotlib which yticks to plot
ax.set_yticks([0,1,2,3])
# labelling the yticks according to your list
ax.set_yticklabels(['A','B','C','D'])
我有一个 x 值列表,我想在 y 轴上绘制(用线条)。
也就是说,如果 x = [3, 5, 2, 4] 且 y = ['A', 'B', 'C', 'D'],则情节可能看起来像这样(除非不是手绘):
恐怕我在 matplotlib.pyplot 文档 / SO / google 中没有看到任何指向正确方向的内容,甚至没有看到它的名称。有什么指点吗?
我想你在找这样的东西
import numpy as np
import matplotlib.pyplot as plt
fig,ax = plt.subplots(1)
# create some x data and some integers for the y axis
x = np.array([3,5,2,4])
y = np.arange(4)
# plot the data
ax.plot(x,y)
# tell matplotlib which yticks to plot
ax.set_yticks([0,1,2,3])
# labelling the yticks according to your list
ax.set_yticklabels(['A','B','C','D'])