This answer, suggests using plt.savefig in order to increase the DPI. I am a relative newbie, and not sure how to use .savefig.

savefig's call signature requires fname to reference the file (or object?) which needs more DPI:

enter image description here

In the following code, what should I use for fname? Should I create an object and then reference that?

#previous code generates two dataframes now converted to two lists... Max_Vals = DFMAX1.tolist() Min_Vals = DFMIN1.tolist() fig = plt.figure() plt.plot(Max_Vals, 'g-') plt.plot(Min_Vals, 'b-') fig.set_size_inches(30.,18.) plt.show() 

enter image description here

When I run savefig without fname:

plt.savefig(dpi=300) 

I get an error:

enter image description here

Grateful for any help.

7

1 Answer

The point of plt.savefig() is it allows you to export the graph to a file. If you're just using plt.show() you're only showing the image, at which point to copy it elsewhere you have to use print-screen or similar.

Try running:

#previous code generates two dataframes now converted to two lists... Max_Vals = DFMAX1.tolist() Min_Vals = DFMIN1.tolist() fig = plt.figure() plt.plot(Max_Vals, 'g-') plt.plot(Min_Vals, 'b-') fig.set_size_inches(30.,18.) plt.savefig('100dpi.png', dpi=100) plt.savefig('200dpi.png', dpi=200) 

At this point, two image files will be saved in your working folder (likely the same folder as your script) - one with 100dpi, the second with 200dpi.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy