-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
RF: always close old figure windows #3916
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
RF: always close old figure windows #3916
Conversation
Doesn't this break one of the reasons for |
Aha - I thought that I had missed something. I can understand the need to build up figures over the course of a few plot directives, and this will break that. On the other hand, accidentally picking up an old figure seems like a bad idea too, and easy to do. I think the current answer would be, always do a That would still not deal with my test case though, where the user called Is there another way of avoiding picking up an old figure by accident? |
|
Yes, I was doing that with an explicit extra hidden plot_directive at the top of the page, but that's pretty ugly and easy to forget. You'd have to do one of those each time you used What about closing all but the last figure on the basis it is most unlikely you'd want the first of two figures in the plot directive display? |
Or just to add a 'close-existing' option that is false by default? At least this would be a good explicit solution, although I am sure there will be some surprised users with the default behavior. |
|
cb4bba2
to
432f5a6
Compare
OK - I added |
All I see here is tests... I also think you need to white-list the tests so that travis will find them. |
I added back the code - bad rebase. I think I whitelisted the tests? |
432f5a6
to
b40e827
Compare
This looks great, and it's nice to finally have some tests for the plot directive. Looking at the Travis logs, though, it does seem that the new tests are not actually being run (even though you've added it to the testing list). I may not have a chance to drill down as to why -- I think this is the only tests we have outside of |
I think the tests aren't being run because sphinx is not installed (the
|
a69de87
to
cbee4f4
Compare
OK - I believe the tests are running and passing now. The tests revealed a Python 2.6 problem, with an easy fix - ah testing. |
@@ -23,7 +23,7 @@ matrix: | |||
env: BUILD_DOCS=true | |||
|
|||
install: | |||
- pip install -q --use-mirrors nose python-dateutil $NUMPY pep8 pyparsing pillow | |||
- pip install -q --use-mirrors nose python-dateutil $NUMPY pep8 pyparsing pillow sphinx |
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.
can you also remove the sphinx installation on line 30?
cbee4f4
to
aa7a399
Compare
Anything more I can do here? |
Can you also add a note in https://github.com/matplotlib/matplotlib/tree/master/doc/users/whats_new ? One of our biggest problems is 'stealth' features that exist but no one knows about. It seems like it would simpler/cleaner to pass the value of |
@matthew-brett This needs a re-base |
886d103
to
e980de6
Compare
Add `close-figs` choice to `context` option of plot_directive. This keeps the current context, but closes any previous figures. This is necessary because the plot directive first runs the specified code, then collects figures with: fig_managers = _pylab_helpers.Gcf.get_all_fig_managers() If you are using the "context" option, prior figures maybe generated from a previous plot directive command, are still open, and therefore collected with the new figure(s). The old figures will usually be earlier in the list, and so, for something like this ReST block, you will always get the first generated figure (``range(10)``) repeated in the second plot directive panel: ####### A title ####### .. plot:: :context: import matplotlib.pyplot as plt plt.plot(range(10)) Then some text. .. plot:: :context: plt.figure() plt.plot(range(5), 'r') This PR add a context option of form `:context: close-figs` that closes any previous figure windows before running the directive code. It also adds a small test sphinx project to test the directive commands. See email discussion thread starting here: https://www.mail-archive.com/[email protected]/msg10816.html
re.flags argument to re.sub appears to a 2.7 innovation.
Add small section on `close-figs` argument for plot directive.
e980de6
to
5e4a602
Compare
Rebased on master. I hope. Had a few glasses of wine for the new year. |
ENH : add option to close figures in plot directive
The plot directive first runs the specified code, then collects figures with::
If you are using the "context" option, prior figures maybe generated from a
previous plot directive command, are still open, and therefore collected with
the new figure(s). The old figures will usually be earlier in the list, and
so, for something like this ReST block, you will always get the first
generated figure (
range(10)
) repeated in the second plot directive panel::A title
#######
This PR always closes previous figure windows before running the plot
directive code.
See email discussion thread starting here:
https://www.mail-archive.com/[email protected]/msg10816.html