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

Skip to content

allow selecting the backend by setting the environment variable MPLBACKEND #3710

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

Merged
merged 6 commits into from
Nov 18, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Added mplDeprecation warning when the -d argument is used. Minor impr…
…ovements to the backend selection documentation.
  • Loading branch information
FlorianRhiem committed Nov 18, 2014
commit 40e40193b37d14afbbac7093a552dbb7d021250e
2 changes: 1 addition & 1 deletion doc/devel/coding_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ external backend via the ``module`` directive. if

> python simple_plot.py -dmodule://my_backend
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you put the space back in there? These docs are for reading, not typing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the code, now I wonder if it ever worked with the space in there...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WeatherGod At least it does not work with module-backends, because the argument without the first two characters is passed to use() and use() contains arg.startswith('module://') without a previous .strip() call.


* with the use directive is your script::
* with the use directive in your script::

import matplotlib
matplotlib.use('module://my_backend')
Expand Down
24 changes: 13 additions & 11 deletions doc/faq/usage_faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,10 @@ pygtk, wxpython, tkinter, qt4, or macosx; also referred to as
"interactive backends") and hardcopy backends to make image files
(PNG, SVG, PDF, PS; also referred to as "non-interactive backends").

There are a four ways to configure your backend, in reversed order
of precedence:
There are a four ways to configure your backend. If they conflict each other,
the method mentioned last in the following list will be used, e.g. calling
:func:`~matplotlib.use()` will override the setting in your ``matplotlibrc``.


#. The ``backend`` parameter in your ``matplotlibrc`` file (see
:ref:`customizing-matplotlib`)::
Expand All @@ -329,9 +331,9 @@ of precedence:

> python script.py -dbackend
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space


This might conflict with scripts which parse
command line arguments (see issue
`#1986 <https://github.com/matplotlib/matplotlib/issues/1986>`_), so you
This method is **deprecated** as the `-d` argument might conflict with
scripts which parse command line arguments (see issue
`#1986 <https://github.com/matplotlib/matplotlib/issues/1986>`_). You
should use :envvar:`MPLBACKEND` instead.

#. If your script depends on a specific backend you can use the
Expand All @@ -340,12 +342,12 @@ of precedence:
import matplotlib
matplotlib.use('PS') # generate postscript output by default

If you use the ``use``, this must be done before importing
:mod:`matplotlib.pyplot`, calling :func:`~matplotlib.use` after pyplot
has been imported will have no effect. Using `use` will
require changes in your code if users want to use a different
backend. Therefore, you should avoid explicitly calling ``use`` unless
absolutely necessary.
If you use the :func:`~matplotlib.use` function, this must be done before
importing :mod:`matplotlib.pyplot`. Calling :func:`~matplotlib.use` after
pyplot has been imported will have no effect. Using
:func:`~matplotlib.use` will require changes in your code if users want to
use a different backend. Therefore, you should avoid explicitly calling
:func:`~matplotlib.use` unless absolutely necessary.

.. note::
Backend name specifications are not case-sensitive; e.g., 'GTKAgg'
Expand Down
6 changes: 5 additions & 1 deletion lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def _forward_ilshift(self, other):

# cbook must import matplotlib only within function
# definitions, so it is safe to import from it here.
from matplotlib.cbook import is_string_like
from matplotlib.cbook import is_string_like, mplDeprecation
from matplotlib.compat import subprocess

try:
Expand Down Expand Up @@ -1373,6 +1373,10 @@ def tk_window_focus():
if s.startswith(str('-d')) and len(s) > 2: # look for a -d flag
try:
use(s[2:])
warnings.warn("Using the -d command line argument to select a "
"matplotlib backend is deprecated. Please use the "
"MPLBACKEND environment variable instead.",
mplDeprecation)
break
except (KeyError, ValueError):
pass
Expand Down