def use(arg, warn=True, force=False):"""Set the matplotlib backend to one of the known backends.
The argument is case-insensitive. *warn* specifies whether a
warning should be issued if a backend has already been set up.
*force* is an **experimental** flag that tells matplotlib to
attempt to initialize a new backend by reloading the backend
module.
.. note::
This function must be called *before* importing pyplot for
the first time; or, if you are not using pyplot, it must be called
before importing matplotlib.backends. If warn is True, a warning
is issued if you try and call this after pylab or pyplot have been
loaded. In certain black magic use cases, e.g.
:func:`pyplot.switch_backend`, 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 suppress the warnings.
To find out which backend is currently set, see
:func:`matplotlib.get_backend`."""
#Lets determine the proper backend name first
if arg.startswith('module://'):
name=argelse:#Lowercase only non-module backend names (modules are case-sensitive)
arg =arg.lower()
name=validate_backend(arg)#Check if we've already set up a backend
if 'matplotlib.backends' insys.modules:#Warn only if called with a different name
if (rcParams['backend'] != name) andwarn:
warnings.warn(_use_error_msg)#Unless we've been told to force it, just return
if notforce:returnneed_reload=Trueelse:
need_reload=False#Store the backend name
rcParams['backend'] =name#If needed we reload here because a lot of setup code is triggered on
#module import. See backends/__init__.py for more detail.
ifneed_reload:
reload(sys.modules['matplotlib.backends'])