Zeeshan
Zeeshan

Reputation: 1288

Plot size changes on saving plot in matplotlib

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

Upvotes: 1

Views: 2105

Answers (1)

Zeeshan
Zeeshan

Reputation: 1288

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')

Upvotes: 1

Related Questions