-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Figure resize when saving a plot #8736
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
This is a side-effect of the work to support high-dpi screens and the need to temporarily double the dpi. What is the dpi on the screen vs the dpi you are saving at? Is it a big change (factor of 2) or a small one? I suspect that this may actually be a bug in the figure size not round-tripping properly rather than in the dpi handling per-say. I am also not sure off the top of my head what is forcing the re-draw in the GUI. Are you using If we are going to go down the route of disabling the auto-redraw can it be done as a context manager (this is one of many things where we should be using context managers, but the code was written before context managers existed 😜 ). |
I would say that it is an approximately 10% reduction in width during the temporary resize. The requested dpi of the PNG file I am saving is 100, and a little googling shows that the Thunderbolt display I am using has a dpi of 109, so that could be consistent. It's puzzling that the value of The GUI subclasses FigureManagerQT, so it is using the If there is a long-term plan that will render this issue moot, then it can probably wait. It's just disconcerting seeing the window suddenly change size, and it took me a while to persuade myself that it reverted back to the same size. |
Probably related to roughly related to #8717 |
I've finally realized what the problem is. When setting the |
As a follow-up, I had already subclassed FigureManagerQT for other reasons. If I add the following resize function to the class, then my problems disappear, i.e., there is no discernible resize of the plotting window, temporary or permanent. I don't think it is related to screen resolutions.
You could presumably do the same thing in FigureManagerQT, since |
that is a very experimentalist approach, I like it 👍 |
exact work:
|
Hello! Can you please tell me how I can solve this issue? I have the exact same problem: I am saving a figure over and over again, so that I can animate it afterwards but the figure keeps shriniking in size after successive saves... I have set a custom |
What version of Matplotlib are you using? This should have been fixed in the 2.2 series. |
Yes you are right, sorry for the spam. Turns out I wasn't up to date with the latest version. Now everything is working properly! |
I'm having the same issue as above, particularly like what @Datseris described. I have a I'm using |
I added lines to explicitly update the canvas and the application every loop, and that seemed to fix the issue. NVM! |
Bug report
Bug summary
The
print_figure
function in theFigureCanvasBase
class records the current figure's dpi, sets it to the requested dpi for the saved figure, and then resets it to the original. Setting the dpi invokes a property function,_set_dpi
that calls the figure'sset_size_inches
method, which then triggers a resize of the figure manager.This resize is not evident when I use the standard Pyplot commands within a Qt console, presumably because the plot size doesn't change. However, I have embedded the Matplotlib figure in a PyQt GUI where I don't have the toolbar in the same widget, and it causes a noticeable size change for a fraction of a second before the second dpi reset restores the old size.
Possible solution
I would like to suggest that the
FigureCanvasBase
print_figure
function should not invoke the dpi property, but set and then reset the figure's hidden variable,_dpi
, which will not trigger the redundant canvas resize. I can submit a pull request, but I wanted to check if there would be side effects.Matplotlib version
The text was updated successfully, but these errors were encountered: