Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c81cb87

Browse files
committed
Merged revisions 5360 via svnmerge from
https://matplotlib.svn.sourceforge.net/svnroot/matplotlib/branches/v0_91_maint ........ r5360 | jdh2358 | 2008-06-02 10:06:41 -0500 (Mon, 02 Jun 2008) | 1 line added switch_backend bugfix from sf patch 1979402 ........ svn path=/trunk/matplotlib/; revision=5361
1 parent 643d15b commit c81cb87

2 files changed

Lines changed: 14 additions & 9 deletions

File tree

lib/matplotlib/__init__.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ def rcdefaults():
740740
or matplotlib.backends is imported for the first time.
741741
"""
742742

743-
def use(arg):
743+
def use(arg, warn=True):
744744
"""
745745
Set the matplotlib backend to one of the known backends.
746746
@@ -752,12 +752,17 @@ def use(arg):
752752
753753
will specify a default of pdf output generated by Cairo.
754754
755-
Note: this function must be called *before* importing pylab
756-
for the first time; or, if you are not using pylab, it must
757-
be called before importing matplotlib.backends.
755+
Note: this function must be called *before* importing pylab for
756+
the first time; or, if you are not using pylab, it must be called
757+
before importing matplotlib.backends. If warn is True, a warning
758+
is issued if you try and callthis after pylab or pyplot have been
759+
loaded. In certain black magic use cases, eg
760+
pyplot.switch_backends, we are doing the reloading necessary to
761+
make the backend switch work (in some cases, eg pure image
762+
backends) so one can set warn=False to supporess the warnings
758763
"""
759764
if 'matplotlib.backends' in sys.modules:
760-
warnings.warn(_use_error_msg)
765+
if warn: warnings.warn(_use_error_msg)
761766
be_parts = arg.split('.')
762767
name = validate_backend(be_parts[0])
763768
rcParams['backend'] = name

lib/matplotlib/pyplot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ def switch_backend(newbackend):
5252
"""
5353
close('all')
5454
global new_figure_manager, draw_if_interactive, show
55-
matplotlib.use(newbackend)
56-
reload(backends)
57-
from backends import new_figure_manager, draw_if_interactive, show
58-
55+
matplotlib.use(newbackend, warn=False)
56+
reload(matplotlib.backends)
57+
from matplotlib.backends import pylab_setup
58+
new_figure_manager, draw_if_interactive, show = pylab_setup()
5959

6060

6161
def isinteractive():

0 commit comments

Comments
 (0)