1

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

Community
  • 1
  • 1
Zeeshan
  • 1,248
  • 1
  • 12
  • 19

1 Answers1

1

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')
Zeeshan
  • 1,248
  • 1
  • 12
  • 19