0

I am plotting many years of data. On the x-axis, I am plotting time of the day and on y-axis the value. The problem is x-axis ticks builtup together, not visible. How do I solve it?

plt.plot(df.index.strftime('%H:%M'),df['ydata'],'.')#hour+ssdf.index.minute/60
plt.gcf().autofmt_xdate()
plt.show()

enter image description here

In the above plot, I wanted to see the x-axis ticks show 00:00, 02:00, etc.

Mainland
  • 4,110
  • 3
  • 25
  • 56
  • When you plot strings on the x-axis, you're telling matplotlib that your data is categorical, and therefore each distinct values needs to be shown. Plot the actual dates and use an axis label formatter instead – Paul H Sep 13 '20 at 20:18
  • See, for instance, https://stackoverflow.com/questions/14946371/editing-the-date-formatting-of-x-axis-tick-labels-in-matplotlib – Paul H Sep 13 '20 at 20:19

1 Answers1

1

You can try the first answer from this post.

Reducing the number of xticks by using plt.xticks will change the frequency of items appearing.

lennertcl
  • 93
  • 6