8000 added documentation on backend selection methods · matplotlib/matplotlib@0ead4b2 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0ead4b2

Browse files
committed
added documentation on backend selection methods
1 parent 0d995d4 commit 0ead4b2

File tree

6 files changed

+53
-15
lines changed

6 files changed

+53
-15
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2014-10-27 Allowed selection of the backend using the `MPLBACKEND` environment
2+
variable. Added documentation on backend selection methods.
3+
14
2014-09-27 Overhauled `colors.LightSource`. Added `LightSource.hillshade` to
25
allow the independent generation of illumination maps. Added new
36
types of blending for creating more visually appealing shaded relief

doc/devel/coding_guide.rst

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,20 @@ external backend via the ``module`` directive. if
270270

271271
backend : module://my_backend
272272

273-
* with the use directive is your script::
274273

275-
import matplotlib
276-
matplotlib.use('module://my_backend')
274+
* with the :envvar:`MPLBACKEND` environment variable::
275+
276+
> export MPLBACKEND="module://my_backend"
277+
> python simple_plot.py
277278

278-
* from the command shell with the -d flag::
279+
* from the command shell with the `-d` flag::
279280

280-
> python simple_plot.py -d module://my_backend
281+
> python simple_plot.py -dmodule://my_backend
281282

283+
* with the use directive is your script::
284+
285+
import matplotlib
286+
matplotlib.use('module://my_backend')
282287

283288
.. _sample-data:
284289

doc/faq/environment_variables_faq.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ Environment Variables
3030
used to find a base directory in which the :file:`matplotlib`
3131
subdirectory is created.
3232

33+
.. envvar:: MPLBACKEND
34+
35+
This optional variable can be set to choose the matplotlib backend. Using the
36+
`-d` command line parameter or the :func:`~matplotlib.use` function will
37+
override this value. See :ref:`what-is-a-backend`.
38+
3339
.. _setting-linux-osx-environment-variables:
3440

3541
Setting environment variables in Linux and OS-X

doc/faq/usage_faq.rst

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,19 +302,37 @@ 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 two primary ways to configure your backend. One is to set
305+
There are a four ways to configure your backend. One is to set
306306
the ``backend`` parameter in your ``matplotlibrc`` file (see
307307
:ref:`customizing-matplotlib`)::
308308

309309
backend : WXAgg # use wxpython with antigrain (agg) rendering
310310

311-
The other is to use the matplotlib :func:`~matplotlib.use` directive::
311+
Another way to do this is setting the :envvar:`MPLBACKEND` environment
312+
variable, either globally or for a single script::
313+
314+
> export MPLBACKEND="module://my_backend"
315+
> python simple_plot.py
316+
317+
To set the backend for a single script, you can alternatively use the `-d`
318+
command line argument::
319+
320+
> python script.py -dbackend
321+
322+
You should be aware though that this might conflict with scripts which use the
323+
command line arguments.
324+
325+
If your script depends on a specific backend you can use the matplotlib
326+
:func:`~matplotlib.use` directive::
312327

313328
import matplotlib
314329
matplotlib.use('PS') # generate postscript output by default
315330

316331
If you use the ``use`` directive, this must be done before importing
317-
:mod:`matplotlib.pyplot` or :mod:`matplotlib.pylab`.
332+
:mod:`matplotlib.pyplot` or :mod:`matplotlib.pylab`. Using this function will
333+
require a change in your code for users who would like to use a different
334+
backend. Therefore you should avoid explicitly calling ``use`` unless
335+
necessary.
318336

319337
.. note::
320338
Backend name specifications are not case-sensitive; e.g., 'GTKAgg'
@@ -325,7 +343,7 @@ binary installer or a linux distribution package, a good default
325343
backend will already be set, allowing both interactive work and
326344
plotting from scripts, with output to the screen and/or to
327345
a file, so at least initially you will not need to use either of the
328-
two methods given above.
346+
methods given above.
329347

330348
If, however, you want to write graphical user interfaces, or a web
331349
application server (:ref:`howto-webapp`), or need a better

doc/users/whats_new.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ Added a :code:`pivot` kwarg to :func:`~mpl_toolkits.mplot3d.Axes3D.quiver`
6060
that controls the pivot point around which the quiver line rotates. This also
6161
determines the placement of the arrow head along the quiver line.
6262

63+
New backend selection
64+
---------------------
65+
66+
The environment variable :envvar:`MPLBACKEND` can now be used to set the
67+
matplotlib backend.
68+
69+
6370
.. _whats-new-1-4:
6471

6572
new in matplotlib-1.4

lib/matplotlib/__init__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,12 +1379,11 @@ def tk_window_focus():
13791379
# we don't want to assume all -d flags are backends, e.g., -debug
13801380
else:
13811381
# no backend selected from the command line, so we check the environment
1382-
# variable MPL_BACKEND
1383-
if 'MPL_BACKEND' in os.environ:
1384-
try:
1385-
use(os.environ['MPL_BACKEND'])
1386-
except (KeyError, ValueError):
1387-
pass
1382+
# variable MPLBACKEND
1383+
try:
1384+
use(os.environ['MPLBACKEND'])
1385+
except (KeyError, ValueError):
1386+
pass
13881387

13891388
default_test_modules = [
13901389
'matplotlib.tests.test_agg',

0 commit comments

Comments
 (0)
0