I recently noticed that setting the dpi for savefig doesn’t work as expected when saving to pdf. Take the following code, for example:
import matplotlib.pyplot as plt
The resulting png file is 800 x 600 (as expected), while the pdf file is 576 x 432 [which is (800 x 600) * 72/100]. I found an old thread suggesting that a dpi of 72 should be hard coded into the PDF renderer for compatibility with older versions of the PDF spec. That makes sense; however, it’d be nice if the docstring for savefig told users about his behavior.
Below, is a patch to the savefig docstring. I’m sure someone else could word this better, but I thought I’d at least try.
P.S. maybe enough time has passed that most people have adopted PDF viewers/parsers using PDF >= 1.6, and this hard-coded dpi could be removed? Just a thought.
— lib/matplotlib/figure.py (revision 8561)
+++ lib/matplotlib/figure.py (working copy)
@@ -1018,7 +1018,10 @@
dpi: [ None | scalar > 0 ]
The resolution in dots per inch. If None it will default to
the value ``savefig.dpi`` in the matplotlibrc file.
the value ``savefig.dpi`` in the matplotlibrc file. NOTE: when
saving to pdf, the dpi will not affect the page dimensions (which
is always 72 dpi), but it will affect the resolution of rasterized
elements in the plot.
the colors of the figure rectangle