Fix use() so that it is possible to reset the rcParam. #1028

merged 1 commit into from Jul 21, 2012


None yet

3 participants


With this change, the warn argument acts as a way to ignore the warning
and force the rcParam change. This allows switch_backend() to actually
function again.


you accidentially added a swap file with this commit.

efiring commented Jul 20, 2012

I strongly oppose this, as explained in my reply to your original email.


I noticed the .swp commit (no idea how that happened). This is a new set of commits that adds a 'force' parameter to use and uses this in switch_backend().

efiring commented Jul 20, 2012

Sorry to be fussy, but I really think the reload needs to be moved from switch_backends to use. In use, if the module was already loaded, then set a flag; and at the end of use, if that flag is set, do the reload. Otherwise there is a mismatch between the state of the system and the rcParams.

Am I missing something here?


I guess not. It seemed like this would have made switch_backend() largely superfluous, but I guess it still has all the pylab setup code.

This is probably yet more clean.


This seems to be working alright.

One more question: I think now I'd like to add a flag that controls whether switch_backend() closes the old figures. Thoughts?

efiring commented Jul 20, 2012

Why would you want to do that? What happens if an old window gets redrawn, or something gets plotted to it, after you have made the switch? Why do you want to do all this switching in the first place? It seems like it is opening up a big can of worms, so it needs a compelling use case.

@efiring efiring commented on an outdated diff Jul 20, 2012
@@ -920,23 +920,37 @@ def use(arg, warn=True):
loaded. In certain black magic use cases, e.g.
:func:`pyplot.switch_backends`, we are doing the reloading necessary to
make the backend switch work (in some cases, e.g. pure image
- backends) so one can set warn=False to supporess the warnings.
+ backends) so one can set warn=False to suppress the warnings.
efiring Jul 20, 2012 Owner

Docstring still needs work to explain exactly what warn and force do.


@efiring, you haven't seen the ipython notebooks, have you? This is the driver for it, to be able to switch back and forth between two backends.


It seems technically possible to continue to run a gui figure in the background while using image figures elsewhere.

I view this as something that is usually a really bad idea, but to have a hook to do it if you claim to know what you are doing. I'd document it as so.

In the same vein of being unsafe, I had started to document the kwargs to use(), but had stopped because I didn't want to encourage anyone to use them. I guess it may be better to be explicit about their danger in a documented fashion.


it seems that we end up closing down the event loop, so the not-closing feature is better left as a thought experiment.

I'll update the docstrings.

efiring commented Jul 20, 2012

On 2012/07/20 11:28 AM, Benjamin Root wrote:

@efiring, you haven't seen the ipython notebooks, have you? This is
the driver for it, to be able to switch back and forth between two

I'm vaguely familiar with it. I think I tried one briefly a while back.
It's still not obvious to me why the notebook application makes it
important to be able to switch backends.


Switching between the image and GUI backends allows you to be able to work with interactive and inline figures within a single notebook. Without switching backends, you have to choose.

@dopplershift dopplershift Fix up switch_backend() and use().
Add an option to use() that allows forcing the configuration change
which also reloads the module as necessary. Fix and slightly refactor
switch_backend() to make use of this functionality.

I see no other reason to withhold this PR. It does fix a definite bug. There are some other issues, but they probably should be addressed in a different PR.

@WeatherGod WeatherGod merged commit 60d869c into matplotlib:master Jul 21, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment