0

I have a dataframe with one column of dtype datetime64. It contains dates from 2017/01/01 (Jan-2017) - 2018/04/01 (April-2018). I used matplotlib.pyplot to plot the dataframe with the Date column in X-axis. But the xticks are longer and overlaps resulting in a graph like this. How can I manage the xticks properly or use a different xtick that contains only month and year, Jan-17. The code I used for plotting:

plt.plot('Date','CODIn',data=df,marker='o',label='Influent')
plt.plot('Date','CODOut',data=df,marker='o',linestyle='dashed',label='Effluent')
plt.legend()    
  • You can either rotate the xticklabels by 45 degree or any other value (as explained [here](https://stackoverflow.com/questions/43152502/how-can-i-rotate-xticklabels-in-matplotlib-so-that-the-spacing-between-each-xtic)) for better presentation OR you can increase your figure width using `fig=plt.figure(figsize=(10, 6))` where 10 is the width and 6 is the height in inches OR you can align the dates vertically using `plt.xticks(rotation='vertical')` – Sheldore Sep 06 '18 at 10:17
  • Dates can be a real pain with `matplotlib`. In addition to the suggestions by Bazingaa, you should also look into using [`matplotlib.dates`](https://matplotlib.org/gallery/api/date.html), specificicaly `DateFormatter` which will allow you to format the ticks appropriately – ALollz Sep 06 '18 at 14:41

0 Answers0