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

Skip to content

Commit 40e4019

Browse files
committed
Added mplDeprecation warning when the -d argument is used. Minor improvements to the backend selection documentation.
1 parent 0042453 commit 40e4019

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

doc/devel/coding_guide.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ external backend via the ``module`` directive. if
280280

281281
> python simple_plot.py -dmodule://my_backend
282282

283-
* with the use directive is your script::
283+
* with the use directive in your script::
284284

285285
import matplotlib
286286
matplotlib.use('module://my_backend')

doc/faq/usage_faq.rst

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,10 @@ pygtk, wxpython, tkinter, qt4, or macosx; also referred to as
302302
"interactive backends") and hardcopy backends to make image files
303303
(PNG, SVG, PDF, PS; also referred to as "non-interactive backends").
304304

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

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

330332
> python script.py -dbackend
331333

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

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

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

350352
.. note::
351353
Backend name specifications are not case-sensitive; e.g., 'GTKAgg'

lib/matplotlib/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def _forward_ilshift(self, other):
180180

181181
# cbook must import matplotlib only within function
182182
# definitions, so it is safe to import from it here.
183-
from matplotlib.cbook import is_string_like
183+
from matplotlib.cbook import is_string_like, mplDeprecation
184184
from matplotlib.compat import subprocess
185185

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

0 commit comments

Comments
 (0)