对于外面的人来说,这应该是一个非常简单的问题。我需要 python 中的线图,其中自变量(x 轴)是Date
. y 轴是相关Value
数据,会有多行:每行Name
描述Value
随时间的变化。除了使用 matplotlib 之外,我不确定如何做到这一点。
这就是我组织df
数据的方式,从 csv 文件中提取数据。
Name = df['Name']
Value = df['expected harvest (Value)']
Date = df['Date']
result = pd.concat([Name, Value, Date], axis=1)
>>> result
Name Value Date
1 189 9.0 11/14/15
2 191 10.0 11/14/15
3 192 1.0 11/14/15
4 193 4.0 11/14/15
... ... ... ...
2948 189 7.0 2/20/16
2950 190 1.0 2/20/16
2952 191 3.0 2/20/16
2953 192 3.0 2/20/16
2954 193 0.0 2/20/16
到目前为止,我已经尝试过了,但是我需要将线条水平而不是垂直,并且每个Name
. 不知何故,我错过了如何将数据分组Name
然后绘制为单独的线。
fig = plt.figure()
ax = fig.add_subplot(111)
x_points = df['Date']
x_points = pd.to_datetime(x_points)
y_points = df['expected harvest (Value)']
p = ax.plot(x_points, y_points, 'b')
ax.set_xlabel('x-points')
ax.set_ylabel('y-points')
ax.set_title('Simple XY point plot')
fig.show()