Search code examples
pythonpython-2.7pdfmatplotlibrasterize

How to save pictures with lower resolution in python?


I need to save figures with many data (10.000 points per figure or more...) in lower resolution, to open them with the pdf viewer more quickly. I've heard that a proper combination of rasterized = True and dpi should be used in pylab.savefig.

What are these arguments? others may be used within savefig for this purpose? Please give a clear example

PD: I have PYTHON 2.7


Solution

  • After ploting or when you get the axis available:

    pylab.gca().set_rasterized(True)
    

    or for every axis ax you know

    ax.set_rasterized(True)
    

    Finally

    pylab.savefig(file_name, dpi=your_choice)
    

    where dpi could be 80, 160, 300, 600, etc.