matplotlib: change timestamp format of x-grid in a bar-chart

痴心易碎 提交于 2019-12-11 03:15:11

问题


I have the following code:

 my_df.plot(x='my_timestamp', y='data_count', kind='bar')

and the output looks like this:

I am wondering is it possible to change the x-grid format, so it will just show 2016-03-14 instead of 2016-03-14 00:00:00

Thanks!


回答1:


There might be a more elegant solution, but what definitely works is to loop over the xticklabels, split them up and only use the first part of the string as a new ticklabel.

ax = df.plot(x='my_timestamp', y='data_count', kind='bar')

ax.set_xticklabels([t.get_text().split(" ")[0] for t in ax.get_xticklabels()])


来源:https://stackoverflow.com/questions/42145062/matplotlib-change-timestamp-format-of-x-grid-in-a-bar-chart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!