Matplotlib x值对y的线图

时间:2015-04-14 14:58:58

标签: python python-3.x matplotlib

我有一个值列表x,我想用y轴绘制(用线条)。

也就是说,如果x = [3,5,2,4]和y = ['A','B','C','D'],情节可能看起来像这样(除非手 - 绘制):

the plot style I mean

而且我害怕我在matplotlib.pyplot docs / SO / google中没有看到任何东西指向我正确的方向,甚至是什么叫它。有什么指针吗?

1 个答案:

答案 0 :(得分:6)

我认为你会找到类似这样的东西

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'])