如何显示分钟:熊猫Jupyter笔记本中情节的时间

时间:2019-06-19 22:38:53

标签: pandas plot time format

Image of the Plot here我的数据框已经具有“小时。分钟”格式的时间,但是在绘制时,该列中的值被视为X轴上的数字。如何以小时:分钟格式,最好以30分钟为单位绘制时间?

Am使用matplotlib.pyplot和mpl_toolkits.axes_grid1进行绘图

下面的代码段-

host = host_subplot(111, axes_class=AA.Axes)

plt.subplots_adjust(right = 0.75)

#par1 = host.twinx()
par2 = host.twinx()

offset = 0
new_fixed_axis = par2.get_grid_helper().new_fixed_axis
par2.axis["right"] = new_fixed_axis(loc="right", axes=par2,
                                        offset=(offset, 0))
par2.axis["right"].toggle(all=True)

host.set_xlim(8, 13)
host.set_ylim(-1, .04)

host.set_xlabel("Time")
host.set_ylabel("ROC")
par2.set_ylabel("SPY")

p1, = host.plot(df['TimeStamp'], df['LongsROC'], label="Longs", color ='green')
p3, = host.plot(df['TimeStamp'], df['ShortsROC'], label="Shorts", color = 'red')
p4, = host.plot(df['TimeStamp'], df['TotalROC'], label="Total", color = 'orange')
p2, = par2.plot(df['TimeStamp'], df['SPY'], label="SPY", color = 'black')

par2.set_ylim(291, 294)

host.legend()

plt.grid(True)
plt.draw()
plt.show()

从所附图像中,您可以看到绘制的直线,将11.59视作一个数字,而不仅仅是我需要的12点正午12点。 以下是从csv中读取的数据帧中的数据-

    LongsROC    ShortsROC   TotalROC    SPY TimeStamp

111 -0.363944 -0.982345 -0.672143 292.73 11.52 112 -0.333455 -1.051296 -0.691213 292.91 11.53 113 -0.352487 -1.081512 -0.715819 292.91 11.55 114 -0.298104 -1.064427 -0.680024 292.93 11.57 115 -0.262799 -1.078123 -0.669141 292.82 11.59 116 -0.324617 -1.166276 -0.744084 293.17 12.37 117 -0.365767 -1.149050 -0.756140 292.97 12.39 Plot image here

0 个答案:

没有答案