@@ -302,19 +302,52 @@ pygtk, wxpython, tkinter, qt4, or macosx; also referred to as
302
302
"interactive backends") and hardcopy backends to make image files
303
303
(PNG, SVG, PDF, PS; also referred to as "non-interactive backends").
304
304
305
- There are a two primary ways to configure your backend. One is to set
306
- the `` backend `` parameter in your `` matplotlibrc `` file (see
307
- :ref: ` customizing- matplotlib`)::
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
308
309
- backend : WXAgg # use wxpython with antigrain (agg) rendering
310
309
311
- The other is to use the matplotlib :func: `~matplotlib.use ` directive::
310
+ #. The ``backend `` parameter in your ``matplotlibrc `` file (see
311
+ :ref: `customizing-matplotlib `)::
312
312
313
- import matplotlib
314
- matplotlib.use('PS') # generate postscript output by default
313
+ backend : WXAgg # use wxpython with antigrain (agg) rendering
315
314
316
- If you use the ``use `` directive, this must be done before importing
317
- :mod: `matplotlib.pyplot ` or :mod: `matplotlib.pylab `.
315
+ #. Setting the :envvar: `MPLBACKEND ` environment
316
+ variable, either for your current shell or for a single script::
317
+
318
+ > export MPLBACKEND="module://my_backend"
319
+ > python simple_plot.py
320
+
321
+ > MPLBACKEND="module://my_backend" python simple_plot.py
322
+
323
+ Setting this environment variable will override the ``backend `` parameter
324
+ in *any * ``matplotlibrc ``, even if there is a ``matplotlibrc `` in your
325
+ current working directory. Therefore setting :envvar: `MPLBACKEND `
326
+ globally, e.g. in your ``.bashrc `` or ``.profile ``, is discouraged as it
327
+ might lead to counter-intuitive behavior.
328
+
329
+ #. To set the backend for a single script, you can alternatively use the `-d `
330
+ command line argument::
331
+
332
+ > python script.py -dbackend
333
+
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
337
+ should use :envvar: `MPLBACKEND ` instead.
338
+
339
+ #. If your script depends on a specific backend you can use the
340
+ :func: `~matplotlib.use ` function::
341
+
342
+ import matplotlib
343
+ matplotlib.use('PS') # generate postscript output by default
344
+
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.
318
351
319
352
.. note ::
320
353
Backend name specifications are not case-sensitive; e.g., 'GTKAgg'
@@ -324,8 +357,8 @@ With a typical installation of matplotlib, such as from a
324
357
binary installer or a linux distribution package, a good default
325
358
backend will already be set, allowing both interactive work and
326
359
plotting from scripts, with output to the screen and/or to
327
- a file, so at least initially you will not need to use either of the
328
- two methods given above.
360
+ a file, so at least initially you will not need to use any of the
361
+ methods given above.
329
362
330
363
If, however, you want to write graphical user interfaces, or a web
331
364
application server (:ref: `howto-webapp `), or need a better
0 commit comments