186
186
#
187
187
# Matplotlib's documentation and examples use both the OO and the pyplot
188
188
# approaches (which are equally powerful), and you should feel free to use
189
- # either (however, it is preferrable pick one of them and stick to it, instead
189
+ # either (however, it is preferable pick one of them and stick to it, instead
190
190
# of mixing them). In general, we suggest to restrict pyplot to interactive
191
191
# plotting (e.g., in a Jupyter notebook), and to prefer the OO-style for
192
192
# non-interactive plotting (in functions and scripts that are intended to be
@@ -289,44 +289,60 @@ def my_plotter(ax, data1, data2, param_dict):
289
289
# "interactive backends") and hardcopy backends to make image files
290
290
# (PNG, SVG, PDF, PS; also referred to as "non-interactive backends").
291
291
#
292
- # There are three ways to configure your backend. If they conflict each other,
293
- # the method mentioned last in the following list will be used, e.g. calling
294
- # :func:`~matplotlib.use()` will override the setting in your ``matplotlibrc``.
292
+ # Selecting a backend
293
+ # -------------------
295
294
#
296
- # #. The :rc:`backend` parameter in your ``matplotlibrc`` file (see
297
- # :doc:`/tutorials/introductory/customizing`)::
295
+ # There are three ways to configure your backend:
296
+ #
297
+ # 1. The :rc:`backend` parameter in your ``matplotlibrc`` file
298
+ # 2. The :envvar:`MPLBACKEND` environment variable
299
+ # 3. The function :func:`matplotlib.use`
300
+ #
301
+ # A more detailed description is given below.
302
+ #
303
+ # If multiple of these are configurations are present, the last one from the
304
+ # list takes precedence; e.g. calling :func:`matplotlib.use()` will override
305
+ # the setting in your ``matplotlibrc``.
306
+ #
307
+ # If no backend is explicitly set, Matplotlib automatically detects a usable
308
+ # backend based on what is available on your system and on whether a GUI event
309
+ # loop is already running. On Linux, if the environment variable
310
+ # :envvar:`DISPLAY` is unset, the "event loop" is identified as "headless",
311
+ # which causes a fallback to a noninteractive backend (agg).
312
+ #
313
+ # Here is a detailed description of the configuration methods:
314
+ #
315
+ # #. Setting :rc:`backend` in your ``matplotlibrc`` file::
298
316
#
299
317
# backend : qt5agg # use pyqt5 with antigrain (agg) rendering
300
318
#
301
- # If no backend is explicitly set in the ``matplotlibrc`` file, Matplotlib
302
- # automatically detects a usable backend based on what is available on your
303
- # system and on whether a GUI event loop is already running.
319
+ # See also :doc:`/tutorials/introductory/customizing`.
320
+ #
321
+ # #. Setting the :envvar:`MPLBACKEND` environment variable:
304
322
#
305
- # On Linux, if the environment variable :envvar:`DISPLAY` is unset, the
306
- # "event loop" is identified as "headless", which causes a fallback to a
307
- # noninteractive backend (agg).
323
+ # You can set the environment variable either for your current shell or for
324
+ # a single script.
308
325
#
309
- # #. Setting the :envvar:`MPLBACKEND` environment variable, either for your
310
- # current shell or for a single script. On Unix::
326
+ # On Unix::
311
327
#
312
- # > export MPLBACKEND=module://my_backend
328
+ # > export MPLBACKEND=qt5agg
313
329
# > python simple_plot.py
314
330
#
315
- # > MPLBACKEND="module://my_backend" python simple_plot.py
331
+ # > MPLBACKEND=qt5agg python simple_plot.py
316
332
#
317
333
# On Windows, only the former is possible::
318
334
#
319
- # > set MPLBACKEND=module://my_backend
335
+ # > set MPLBACKEND=qt5agg
320
336
# > python simple_plot.py
321
337
#
322
338
# Setting this environment variable will override the ``backend`` parameter
323
339
# in *any* ``matplotlibrc``, even if there is a ``matplotlibrc`` in your
324
- # current working directory. Therefore setting :envvar:`MPLBACKEND`
340
+ # current working directory. Therefore, setting :envvar:`MPLBACKEND`
325
341
# globally, e.g. in your ``.bashrc`` or ``.profile``, is discouraged as it
326
342
# might lead to counter-intuitive behavior.
327
343
#
328
- # #. If your script depends on a specific backend you can use the
329
- # :func:`~ matplotlib.use` function ::
344
+ # #. If your script depends on a specific backend you can use the function
345
+ # :func:`matplotlib.use`::
330
346
#
331
347
# import matplotlib
332
348
# matplotlib.use('PS') # generate postscript output by default
@@ -339,9 +355,9 @@ def my_plotter(ax, data1, data2, param_dict):
339
355
# use a different backend. Therefore, you should avoid explicitly calling
340
356
# `~matplotlib.use` unless absolutely necessary.
341
357
#
342
- # .. note::
343
- # Backend name specifications are not case-sensitive; e.g., 'GTK3Agg'
344
- # and 'gtk3agg' are equivalent.
358
+ #
359
+ # The builtin backends
360
+ # --------------------
345
361
#
346
362
# With a typical installation of matplotlib, such as from a
347
363
# binary installer or a linux distribution package, a good default
@@ -424,6 +440,10 @@ def my_plotter(ax, data1, data2, param_dict):
424
440
# This backend can be activated in IPython with ``%matplotlib wx``.
425
441
# ========= ================================================================
426
442
#
443
+ # .. note::
444
+ # The names of builtin backends case-insensitive; e.g., 'Qt5Agg' and
445
+ # 'qt5agg' are equivalent.
446
+ #
427
447
# .. _`Anti-Grain Geometry`: http://antigrain.com/
428
448
# .. _Postscript: https://en.wikipedia.org/wiki/PostScript
429
449
# .. _`Portable Document Format`: https://en.wikipedia.org/wiki/Portable_Document_Format
@@ -438,7 +458,7 @@ def my_plotter(ax, data1, data2, param_dict):
438
458
# .. _PyQt5: https://riverbankcomputing.com/software/pyqt/intro
439
459
#
440
460
# ipympl
441
- # ------
461
+ # ^^^^^^
442
462
#
443
463
# The Jupyter widget ecosystem is moving too fast to support directly in
444
464
# Matplotlib. To install ipympl
@@ -458,13 +478,13 @@ def my_plotter(ax, data1, data2, param_dict):
458
478
# for more details.
459
479
#
460
480
# GTK and Cairo
461
- # -------------
481
+ # ^^^^^^^^^^^^^
462
482
#
463
483
# `GTK3` backends (*both* `GTK3Agg` and `GTK3Cairo`) depend on Cairo
464
484
# (pycairo>=1.11.0 or cairocffi).
465
485
#
466
486
# How do I select PyQt4 or PySide?
467
- # --------------------------------
487
+ # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
468
488
#
469
489
# The `QT_API` environment variable can be set to either `pyqt` or `pyside`
470
490
# to use `PyQt4` or `PySide`, respectively.
@@ -473,10 +493,18 @@ def my_plotter(ax, data1, data2, param_dict):
473
493
# :mod:`matplotlib` first tries to import it, if the import fails, it tries to
474
494
# import `PySide`.
475
495
#
496
+ # Using non-builtin backends
497
+ # --------------------------
498
+ # More generally, any importable backend can be selected by using any of the
499
+ # methods above. If `name.of.the.backend` is the module containing the backend,
500
+ # use `module://name.of.the.backend` as the backend name, e.g.
501
+ # `matplotlib.use('module://name.of.the.backend')`.
502
+ #
503
+ #
476
504
# .. _interactive-mode:
477
505
#
478
506
# What is interactive mode?
479
- # ===================================
507
+ # =========================
480
508
#
481
509
# Use of an interactive backend (see :ref:`what-is-a-backend`)
482
510
# permits--but does not by itself require or ensure--plotting
@@ -509,7 +537,8 @@ def my_plotter(ax, data1, data2, param_dict):
509
537
# Interactive mode works with suitable backends in ipython and in
510
538
# the ordinary python shell, but it does *not* work in the IDLE IDE.
511
539
# If the default backend does not support interactivity, an interactive
512
- # backend can be explicitly activated using any of the methods discussed in `What is a backend?`_.
540
+ # backend can be explicitly activated using any of the methods discussed
541
+ # in `What is a backend?`_.
513
542
#
514
543
#
515
544
# Interactive example
@@ -522,18 +551,15 @@ def my_plotter(ax, data1, data2, param_dict):
522
551
# plt.ion()
523
552
# plt.plot([1.6, 2.7])
524
553
#
525
- # Assuming you are running version 1.0.1 or higher, and you have
526
- # an interactive backend installed and selected by default, you should
527
- # see a plot, and your terminal prompt should also be active; you
528
- # can type additional commands such as::
554
+ # This will pop up a plot window. Your terminal prompt will remain active, so
555
+ # that you can type additional commands such as::
529
556
#
530
557
# plt.title("interactive test")
531
558
# plt.xlabel("index")
532
559
#
533
- # and you will see the plot being updated after each line. Since version 1.5,
534
- # modifying the plot by other means *should* also automatically
535
- # update the display on most backends. Get a reference to the :class:`~matplotlib.axes.Axes` instance,
536
- # and call a method of that instance::
560
+ # On most interactive backends, the figure window will also be updated if you
561
+ # change it via the object-oriented interface. E.g. get a reference to the
562
+ # `~matplotlib.axes.Axes` instance, and call a method of that instance::
537
563
#
538
564
# ax = plt.gca()
539
565
# ax.plot([3.1, 2.2])
0 commit comments