-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Qt4Agg backend changes figure size #9913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@ImportanceOfBeingErnest Thanks for the neat illustrations of the issue :). I cannot reproduce this on Linux (Arch 4.13.12), with Python 2.7.11 (from conda) and Matplotlib 2.1.0 and master (from git), with the Qt5Agg and Qt4Agg backends. Would this suggest the problem to be a platform specific issue? |
I've done some further tests:
So there are actually 2 issues here: The fact that the figure is smaller in PyQt window is present throughout matplotlib versions. The fact that it shrinks each time it is saved is an issue with matplotlib 2 compared to matplotlib 1.5. |
Not an issue macOS python3, QT5 or macosx backends. (Sorry, can't test QT4 ;-). I've labelled as above... |
There is a feedback loop in the GUI code that resizes the MPL-figure to fit into the window (ex if you drag the window bigger) and if you resize the figure from python the size is forwarded to the GUI (which then may slightly re-size the |
I am not exactly sure, but I just started noticing the figures that were normal size now shrinks in Jupyter Notebook. I run this command to set figure size When I run this suite of code again, it seems to give the right sized figure as before. I am on Windows 10 with 32-bit Python 2.7 (Anaconda), and Matplotlib 2.1 |
@bidhya Issues with the inline backend are probably un-related to this issue. |
Thank you @tacaswell . I think the problem could be related new Pandas 0.22.0 which I updated this morning. Started noticing this change in plot size with Pandas plot functions. |
I confirm the bug exists, it is Windows- and Qt-backend specific. In both Windows 10 and Ubuntu 17.10 I have
The problem is not directly related to Jupyter/Ipython. I typically run my scripts from Spyder (currently 3.2.6) in its IPython console, where I experience the problem. If I run a script from Spyder but in an external system terminal I do have the shrinkage with Qt5agg backend and don't have it with TkAgg. A workaround for me is to do |
the issue is described here: matplotlib/matplotlib#9913
I think this may be effectively fixed (at least the repeated size changes upon savefig) by #10292? |
I put the following command on a separate cell by itself in jupyter notebook. |
@bidhya Would you mind leaving this issue for the problem concerning the QT backend? If you have a problem with the |
@ImportanceOfBeingErnest can you test with the current master branch? |
@tacaswell I cannot test with the complete master, but when taking the backend_bases.py from the current master and running the above code, the automatic shrinking is indeed not observable anymore. In that sense I can confirm that #10292 fixes the repeated size changes upon savefig as suggested by @anntzer above. |
To give another example of this issue, which might make it more obvious and also show more clearly why it is annoying, consider the following: The following code is expected to draw a figure on screen, then allow the user to interactively change it (e.g. pan/zoom etc) and then save it using a different figure size and dpi upon pressing the key
Expected outcome of this code is a saved png file with 1800 x 1800 pixels. What's more is that once The same script using "TkAgg" works as expected (although pressing |
I met the same issue on win8.1 and Qt4. I tried showing figures with (width, height) from (2, 2) to (9, 9). The shrinking always happens in the height dimension and the reduced size is exactly 0.02 inches. When the figure is draw the first time, the size is correct. But after any interaction (no resizing) with the figure, the height will be reduced by 0.02. When the size is too small or too large (exceeding your monitor), it will be set to the min or max value. The code to reproduce the issue
The reduced size seems related to some margin in the height direction. |
Is this still a problem? |
While some of the tangential problems have been fixed in the meantime, the original problem is still present, that is, a figure that should be (6.4, 4.8) inches becomes (6.4, 4.78) inches when drawn with the QT backend on windows. |
At 100 dpi, 4-8-4.78 == 22 pixels, which is the size of the statusbar. We only check the size hint for that, and then calculate a window size from it; I'd guess that if you check https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/backends/backend_qt5.py#L573 the |
The statusbar is removed in the default setup on master, so perhaps this is fixed now? |
Either way, we no longer support Qt4. |
Edit: Note that this issue is also still present with Qt5Agg and matplotlib 3.0.1
Showing a figure with Qt4Agg backend changes the figure size. This is observed with Windows 8.1, python 2.7, matplotlib 2.1.
The original figure is
[ 6.4 4.8]
. After the figure is drawn (and in this case you press a key), it is only[ 6.4 4.78]
.One could argue that this is only a small amount, but saving the figure from within the event loop now gives a different figure size of the saved figure. To make this more obvious, consider the following code which saves a new image after each press of space.
resulting in

Is this a problem of PyQt4? Can anyone reproduce this outside of Windows 8?
The text was updated successfully, but these errors were encountered: