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
@@ -426,6 +442,10 @@ def my_plotter(ax, data1, data2, param_dict):
426
442
# This backend can be activated in IPython with ``%matplotlib wx``.
427
443
# ========= ================================================================
428
444
#
445
+ # .. note::
446
+ # The names of builtin backends case-insensitive; e.g., 'Qt5Agg' and
447
+ # 'qt5agg' are equivalent.
448
+ #
429
449
# .. _`Anti-Grain Geometry`: http://antigrain.com/
430
450
# .. _Postscript: https://en.wikipedia.org/wiki/PostScript
431
451
# .. _`Portable Document Format`: https://en.wikipedia.org/wiki/Portable_Document_Format
@@ -440,7 +460,7 @@ def my_plotter(ax, data1, data2, param_dict):
440
460
# .. _PyQt5: https://riverbankcomputing.com/software/pyqt/intro
441
461
#
442
462
# ipympl
443
- # ------
463
+ # ^^^^^^
444
464
#
445
465
# The Jupyter widget ecosystem is moving too fast to support directly in
446
466
# Matplotlib. To install ipympl
@@ -460,13 +480,13 @@ def my_plotter(ax, data1, data2, param_dict):
460
480
# for more details.
461
481
#
462
482
# GTK and Cairo
463
- # -------------
483
+ # ^^^^^^^^^^^^^
464
484
#
465
485
# `GTK3` backends (*both* `GTK3Agg` and `GTK3Cairo`) depend on Cairo
466
486
# (pycairo>=1.11.0 or cairocffi).
467
487
#
468
488
# How do I select PyQt4 or PySide?
469
- # --------------------------------
489
+ # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
470
490
#
471
491
# The `QT_API` environment variable can be set to either `pyqt` or `pyside`
472
492
# to use `PyQt4` or `PySide`, respectively.
@@ -475,10 +495,18 @@ def my_plotter(ax, data1, data2, param_dict):
475
495
# :mod:`matplotlib` first tries to import it, if the import fails, it tries to
476
496
# import `PySide`.
477
497
#
498
+ # Using non-builtin backends
499
+ # --------------------------
500
+ # More generally, any importable backend can be selected by using any of the
501
+ # methods above. If `name.of.the.backend` is the module containing the backend,
502
+ # use `module://name.of.the.backend` as the backend name, e.g.
503
+ # `matplotlib.use('module://name.of.the.backend')`.
504
+ #
505
+ #
478
506
# .. _interactive-mode:
479
507
#
480
508
# What is interactive mode?
481
- # ===================================
509
+ # =========================
482
510
#
483
511
# Use of an interactive backend (see :ref:`what-is-a-backend`)
484
512
# permits--but does not by itself require or ensure--plotting
@@ -511,7 +539,8 @@ def my_plotter(ax, data1, data2, param_dict):
511
539
# Interactive mode works with suitable backends in ipython and in
512
540
# the ordinary python shell, but it does *not* work in the IDLE IDE.
513
541
# If the default backend does not support interactivity, an interactive
514
- # backend can be explicitly activated using any of the methods discussed in `What is a backend?`_.
542
+ # backend can be explicitly activated using any of the methods discussed
543
+ # in `What is a backend?`_.
515
544
#
516
545
#
517
546
# Interactive example
@@ -524,18 +553,15 @@ def my_plotter(ax, data1, data2, param_dict):
524
553
# plt.ion()
525
554
# plt.plot([1.6, 2.7])
526
555
#
527
- # Assuming you are running version 1.0.1 or higher, and you have
528
- # an interactive backend installed and selected by default, you should
529
- # see a plot, and your terminal prompt should also be active; you
530
- # can type additional commands such as::
556
+ # This will pop up a plot window. Your terminal prompt will remain active, so
557
+ # that you can type additional commands such as::
531
558
#
532
559
# plt.title("interactive test")
533
560
# plt.xlabel("index")
534
561
#
535
- # and you will see the plot being updated after each line. Since version 1.5,
536
- # modifying the plot by other means *should* also automatically
537
- # update the display on most backends. Get a reference to the :class:`~matplotlib.axes.Axes` instance,
538
- # and call a method of that instance::
562
+ # On most interactive backends, the figure window will also be updated if you
563
+ # change it via the object-oriented interface. E.g. get a reference to the
564
+ # `~matplotlib.axes.Axes` instance, and call a method of that instance::
539
565
#
540
566
# ax = plt.gca()
541
567
# ax.plot([3.1, 2.2])
0 commit comments