Saving images in python with very high quality

How can I save python graphics at very high quality?

That is, when I continue to enlarge the object saved in the PDF file, there is no blur?

Also, what would be the best way to save it?

png , eps ? Or some other? I cannot do pdf because there is a hidden number that happens to mess with Latexmk compilation.

+47
python matplotlib save graphics
Apr 24 '13 at 4:38
source share
3 answers

If you are using matplotlib and trying to get good numbers in a latex document, save it as eps. In particular, try something like this after running the commands to build the image:

 plt.savefig('destination_path.eps', format='eps', dpi=1000) 

I found that eps files work best, and the dpi option is what really makes them look good in the document.

UPDATE:

To indicate the orientation of the drawing before saving, simply call the following before calling plt.savefig , but after creating the graph (assuming that you built using axes named ax ):

 ax.view_init(elev=elevation_angle, azim=azimuthal_angle) 

Where elevation_angle is the number (in degrees) that defines the polar angle (down from the vertical z axis), and azimuthal_angle indicates the azimuthal angle (around the z axis).

I believe that the easiest way to determine these values ​​is to first build an image, and then rotate it and observe how the current values ​​of the angles appear at the bottom of the window just below the actual graph. Keep in mind that the x, y, z positions appear by default, but are replaced by two angles when you start to click + drag + rotate the image.

+67
Apr 24 '13 at 4:55
source share

Just to add my results, also using matplotlib.

.eps made all the text bold and removed the transparency .. svg gave me high-resolution photos that actually looked like my timeline.

 import matplotlib.pyplot as plt fig, ax = plt.subplots() # Do the plot code fig.savefig('myimage.svg', format='svg', dpi=1200) 

I used 1200 dpi because many scientific journals require images at 1200/600/300 dpi depending on what the image is. Convert to the desired dpi and format in GiMP or Inkscape.

EDIT: Obviously, dpi doesn't matter, since .svg are vector graphics and have "infinite resolution".

+30
Oct. 16 '14 at 10:33
source share

Well, I found that spencerlyon2 responds to work, however, in case someone finds out not knowing what to do with this single line, I should have done it like this:

 beingsaved = plt.figure() # some scatters plt.scatter(X_1_x, X_1_y) plt.scatter(X_2_x, X_2_y) beingsaved.savefig('destination_path.eps', format='eps', dpi=1000) 
0
Nov 20 2018-11-17T00:
source share



All Articles