Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

X-axis labels getting overlapped while saving matplotlib graph

I am creating some graphs using Matplotlib and later saving them using plt.savefig()

import matplotlib.pyplot as plt
plt.plot(date_list, variable_proj_hr_list, label=prj) # hours vs dates graph
plt.xlabel('Dates')
plt.ylabel('Hours')
plt.title('Hours spent by the team on different Projects day-wise')
plt.legend()
plt.savefig('img1.jpg')

But the image gets saved as follows with all the dates overlapped –

Hours vs Dates Graph

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is there any way I can get the dates not to overlap?

Even if I can maybe increase the width of the image while saving it, or get the dates tilted at an angle such that they appear distinct can solve the problem for me

Any help is highly appreciated!

>Solution :

You can rotate the xticks using:

plt.xticks(rotation=45)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading