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

2
  • Do you want only a .png file? If not have your tried .pdf ? Commented Jul 28, 2015 at 15:17
  • Yes, I want the .png . I found the solutions and posted it as well Commented Jul 28, 2015 at 15:22

1 Answer 1

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')
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I was having the same problem and couldn't figure out what I was doing wrong :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.