1
votes

I have plotted a graph with 14 subplots in matplotlib. In the window the plot looks like this-enter image description here

I save this plot using following command-

import matplotlib.pyplot as plt
plt.savefig('img.png')

But the image that is saved looked like this- enter image description here

Notice that the x axis labels get overlapped because the image is shrinked. The savefig() function has optional argument dpi, but it changes the resolution/quality of saved plot.

I also tried this, but it is used to improve image resolution.

I want the axis labels to be nicely spaced as in the window. Thanks

1
Do you want only a .png file? If not have your tried .pdf ?Srivatsan
Yes, I want the .png . I found the solutions and posted it as wellZeeshan

1 Answers

1
votes

Ok, So I found the solution myself and posting it here for anyone who might face similar problem. I changed the figure size before saving and following code does the trick-

import matplotlib.pyplot as plt
fig =plt.gcf()
fig.set_size_inches(20, 11,dpi=100)
plt.savefig('img.png')