-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FIX: set internal flags first in FigureCanvasBase #5150
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
Conversation
If interactive mode is on using the model where every time any artist is invalidated/marked as stale a `draw_idle` is triggered and the user is using a non-Agg based backend, saving a png will result in a draw_idle call triggered from inside the __init__ method of `FigureCanvasBase` which then fails because the full object has not been set up (this is not a problem using the IPython hooks because the stale state is only checked once when all user code has completed executing). closes matplotlib#5094
I've been looking at it, but I don't completely understand the sequence of events. Setting |
I don't think it will drop a screen update as saving figures goes through The whole Another option is to remove |
I don't object to the changes you already have in here; but your last suggestion sounds good, too. Having |
This is not part of the state of the figure that will trigger a re-drawing. If the user resets the canvas, it is their responsibility to schedule the redraw.
Yes, but it seems something else is going on, I threw a print statement in >>> import matplotlib
>>> matplotlib.use('svg')
>>> import matplotlib.pyplot as plt
>>> plt.ion()
>>> plt.plot(range(3))
[<matplotlib.lines.Line2D object at 0x7f37e065acc0>]
>>> plt.savefig('test.png')
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
drawing
>>> |
Set the `_is_saving` flag as early as possible in `print_figure` to prevent aggressive auto-drawing during the same process.
644b4b2 fixed the excessive drawing issue: import matplotlib
matplotlib.use('svg')
import matplotlib.pyplot as plt
plt.ion()
plt.plot(range(3))
plt.savefig('test.png') (dd_35) ✔ /tmp
19:05 $ python blarg.py
drawing
(dd_35) ✔ /tmp
19:06 $ 12:44 $ git diff
diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py
index b640fed..a85626d 100644
--- a/lib/matplotlib/figure.py
+++ b/lib/matplotlib/figure.py
@@ -1052,7 +1052,7 @@ class Figure(Artist):
Render the figure using :class:`matplotlib.backend_bases.RendererBase`
instance *renderer*.
"""
-
+ print('drawing')
# draw the figure bounding box, perhaps none for white figure
if not self.get_visible():
return
|
This is looking better now! I see that the |
File "/home/travis/build/matplotlib/matplotlib/venv/lib/python2.6/site-packages/matplotlib-1.5.0rc1+100.g3b75d4f-py2.6-linux-x86_64.egg/matplotlib/tests/test_backend_ps.py", line 54, in _test_savefig_to_stringio This is the second time we have gotten this error in one Travis build on this PR. It is starting to make me wonder whether there is in fact a timing problem; but I wouldn't expect that with a non-interactive backend test. There should be only one thread, and everything should be proceeding deterministically. |
Most of those will be caught by traitlets. |
Random thrashing to prevent the intermittent failures
I tried re-working those tests a bit, I don't fully trust the multi-process thing that nose does. |
See #5152 for why I think this is happening. I can go either way on pulling the last commit off of this PR. I like being more explicit about the tests for it's own sake, but am not willing to argue about it ;) |
FIX: set internal flags first in FigureCanvasBase
If interactive mode is on using the model where every time any artist is
invalidated/marked as stale a
draw_idle
is triggered and the user isusing a non-Agg based backend, saving a png will result in a draw_idle
call triggered from inside the init method of
FigureCanvasBase
which then fails because the full object has not been set up (this is
not a problem using the IPython hooks because the stale state is only
checked once when all user code has completed executing).
closes #5094
attn @mdehoon