Using Matplotlib with TKAgg or Qt5Agg backend on 4

2020-07-16 09:08发布

问题:

I'm using Matplotlib 2.0 with Python 3.6 on Ubuntu 16.04 to create plots of data. The computer monitor is 4k resolution at 3840x2160. Plot figures appear really small with tiny font:

I have tried the TKAgg and Qt5Agg backends for Matplotlib but the figure window still appears small on my 4K display.

Can the backend be configured to scale the figure windows for better viewing on high resolution displays?

回答1:

You can tell matplotlib to create a high dpi figure using

plt.figure(dpi=300)

before creating your plot. You can save your plot in higher dpi using:

plt.savefig("figurename.png", dpi=300)


回答2:

One thing you will want to do is set your tk scaling factor properly. Add a tk scaling command to your .wishrc file. The tk scaling wiki page has a couple of tools that can be used to determine the proper scaling factor.

This might help, but most likely, whoever wrote TkAgg will also need to put in some work to make their application work better on high resolution displays (it is mostly possible). In general, too many programs are written around pixel sizes (where the real size changes depending on resolution) and not points or mm.

And your display might turn out worse, as the plot canvas will not scale and other widgets and font might scale properly.

As this is a canvas display, getting the scaling to work properly will be a lot of hard work.

You may have to find a fast way to switch your monitor resolution back and forth so that you can get your work done.

References: tk scaling , tk scaling (wiki)