It seems to be a well-known problem that matplotlib has issues correctly rendering figures on high-DPI displays. There appears to be a Jupyter workaround involving %matplotlib inline
syntax, but this syntax does not work in a standalone python script. How can I apply this kind of workaround to a vanilla Python3 script (i.e. one not in a Jupyter notebook)?
Note that I don't actually care about displaying the figures on the system I'm generating them on - I'm just encoding them into PNG images. I would love to be able to set matplotlib to ignore my system DPI altogether, but it seems to be a deliberate design choice to couple the library's function with the properties of the physical system it's running on (and to prevent direct specification of image dimensions in pixel units). The result is that, on my particular machine, setting a dpi of 100
and a figure size of 1.5
produces an image 300px
in size, not 150px
as expected.