-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix draw on show #4503
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
Fix draw on show #4503
Conversation
If a window is shown due to being in interactive mode, call draw_idle. This draw will be executed when the next time python is idle. This makes running plotting scripts with python -i test.py correctly auto-display/draw when dropping into the repl.
With the repl callback the pyplot function do not need to call `draw_if_interactive`.
note to self: look at how nbagg deals with this (which is a bit funny) and maybe currently broken. @OceanWolf You should be aware of this for your Gcf related PR. |
Ahh, thanks for the heads up. |
@tacaswell , is the note to self an indication that you want to expand this PR to include nbagg, or that nbagg would need to be worked on in a separate PR? |
@@ -1236,6 +1236,7 @@ def new_figure_manager_given_figure(num, figure): | |||
figmgr = frame.get_figure_manager() | |||
if matplotlib.is_interactive(): | |||
figmgr.frame.Show() | |||
figure.canvas.draw_idle() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I seem to recall that draw_idle() in wx can be broken sometimes. Would it make sense to make all of these be figure.canvas.draw()
instead as this isn't a performance-critical portion of the code? We should probably guarantee an image upon initial display.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mdehoon convinced me that in almost all cases we want to use draw_idle
to play nice with the crankier event loops (and most of the backends have some 'I have been told to draw, but have not' so the later calls to draw_idle
get no-oped, rather than stacking up draw commands.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, now re-reading this and understanding it correctly. I think you are reffering to the issue fixed by #3905 so I am inclined to leave this as-is unless a Wx users says otherwise.
- white space clean up - removed dead (commented out) code
- moved `is_interactive` import to top of file - remove unused import (contextmanager, backend_agg)
dicts have a len, do not need to get length of the values list/iterator.
Removing the `draw_if_interactive` from `pyplot.figure` in b2fbae7 causes the figures to no longer be shown on creation in nbagg, this special-cases the manager creating in nbagg to ensure that the figure is indeed shown. The root cause of this is that unlike every other backend which call `show` in either the Manager `__init__` or one of the `new_figure_manager` functions, nbagg did not
I think this ready to go again. |
There is still one `draw_if_interactive` left in the `rcdefaults` call as the current scheme does not track when rcparams change.
Fixes one of the issues raised in comments on b2fbae7
This needs testing on gtk, gkt3, wx, and osx, but I am pretty confident it will work (or at least do no harm).