pythongraphicsmatplotlibsave

Saving images in Python at a very high quality


How can I save Python plots at very high quality?

That is, when I keep zooming in on the object saved in a PDF file, why isn't there any blurring?

Also, what would be the best mode to save it in?

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


Solution

  • If you are using Matplotlib and are trying to get good figures in a LaTeX document, save as an EPS. Specifically, try something like this after running the commands to plot the image:

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

    I have found that EPS files work best and the dpi parameter is what really makes them look good in a document.

    To specify the orientation of the figure before saving, simply call the following before the plt.savefig call, but after creating the plot (assuming you have plotted using an axes with the name ax):

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

    Where elevation_angle is a number (in degrees) specifying the polar angle (down from vertical z axis) and the azimuthal_angle specifies the azimuthal angle (around the z axis).

    I find that it is easiest to determine these values by first plotting the image and then rotating it and watching the current values of the angles appear towards the bottom of the window just below the actual plot. Keep in mind that the x, y, z, positions appear by default, but they are replaced with the two angles when you start to click+drag+rotate the image.