我已经写了代码,绘制了过去七天的股票价值,供用户决定的股票市场随着时间的推移。
我遇到的问题是,我想将x轴格式化为YYMMDD格式。
我也不明白x轴末端的2.014041e7
是什么意思。
x的值为:
20140421.0, 20140417.0, 20140416.0, 20140415.0, 20140414.0, 20140411.0, 20140410.0
y的值为:
531.17, 524.94, 519.01, 517.96, 521.68, 519.61, 523.48
我的代码如下:
mini = min(y)
maxi = max(y)
minimum = mini - 75
maximum = maxi + 75
mini2 = int(min(x))
maxi2 = int(max(x))
plt.close('all')
fig, ax = plt.subplots(1)
pylab.ylim([minimum,maximum])
pylab.xlim([mini2,maxi2])
ax.plot(x, y)
ax.plot(x, y,'ro')
ax.plot(x, m*x + c)
ax.grid()
ax.plot()
当使用您的方法绘制数据时,您只需根据
x
中的数字(浮点数)绘制y
数据,例如20140421.0
(我假设您希望是指2014年4月21日)。您需要将这些浮动中的数据转换为适当的格式,以便matplotlib能够理解。下面的代码获取两个列表(x,y)并转换它们。
整个代码都有注释,因此应该很容易解释。各模块的详细信息如下:
相关问题 更多 >
编程相关推荐