[英]python plt x axis scale is different from data
My data set looks like:我的数据集看起来像:
Month DeviceType AvgRevenue
0 201608 desktop 3.029642
1 201608 mobile 0.197588
2 201608 tablet 1.575810
3 201609 desktop 2.352156
4 201609 mobile 0.182009
And I try to draw a plot to visualize it, however, the x-axis is different from the original data, since my x-axis should be Year and month, the x-axis that the plot shows is not reasonable...How can I correct this?我试着画一个图来可视化它,但是,x轴与原始数据不同,因为我的x轴应该是年和月,图显示的x轴不合理......如何我可以纠正这个吗? Thanks!!
谢谢!!
fig, ax = plt.subplots()
for name, group in device.groupby('DeviceType'):
group.plot('Month', y='AvgRevenue', ax=ax, label=name)
我通过将设备 ['Month'] 转换为日期时间来解决这个问题: device['Month'] = pd.to_datetime(device['Month'], format='%Y%M')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.