How to change DPI in Matplotlib

Matplotlib can be used to output plot to PNG image files. To render for this bitmap format, Matplotlib uses a default DPI of 100. This is a surprisingly low DPI for plots. Thankfully, the DPI can be changed easily.

You can specify the DPI when you save a plot to a file:

using matplotlib.pyplot as mplot
mplot.savefig("foo.png", dpi=300)

If you want this DPI to be used for all output by Matplotlib, then set this line in your matplotlibrc file: