问题
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