[Matplotlib-users] Exporting plot with given scale and DPI

Alexander Bruy alexander.bruy at gmail.com
Mon Jan 8 11:44:26 EST 2018

Hi all.

I use matplotlib inside PyQt app and want to export plot into PNG image with
some user-defined scale and DPI. So after printing that image I should be able
to measure on the paper according to the scale.

For example, length of the profile line is 500m (this is my x-axis),
scale set to 1:10000 and DPI is 150. 500m at 1:10000 should result in
a 5cm print out. Taking 150 DPI into account resulting bitmap should
be 295 pixels wide:

 1cm is 0.393701 inches
 5cm is 1.968505 inches
 1.968505inches * 150DPI = 295.27575 px

Also it is necessary to take into account that resulting image may be
really big, for
example if profile line length is several kilometers and DPI is 600.

As I can see there is a 'dpi' parameter in the savefig() call, but I
can't figure out how
to adjust size of the existing figure when exporting. Can you help me?

Alexander Bruy

More information about the Matplotlib-users mailing list