Skip to content

Commit

Permalink
Merge branch 'v3.7.0-doc' into v3.7.x
Browse files Browse the repository at this point in the history
  • Loading branch information
QuLogic committed Mar 4, 2023
2 parents 66232bc + bdd63bc commit 250cca9
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 9 deletions.
Binary file added doc/_static/FigureInline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/_static/FigureNotebook.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/_static/FigureQtAgg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions doc/_static/zenodo_cache/7637593.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 41 additions & 4 deletions doc/users/explain/figures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,57 @@ using Matplotlib, and what :ref:`Backend <what-is-a-backend>` you are using.
Notebooks and IDEs
------------------

.. figure:: /_static/FigureInline.png
:alt: Image of figure generated in Jupyter Notebook with inline backend.
:width: 400

Screenshot of a `Jupyter Notebook <https://jupyter.org>`_, with a figure
generated via the default `inline
<https://github.com/ipython/matplotlib-inline>`_ backend.


If you are using a Notebook (e.g. `Jupyter <https://jupyter.org>`_) or an IDE
that renders Notebooks (PyCharm, VSCode, etc), then they have a backend that
will render the Matplotlib Figure when a code cell is executed. One thing to
be aware of is that the default Jupyter backend (``%matplotlib inline``) will
by default trim or expand the figure size to have a tight box around Artists
added to the Figure (see :ref:`saving_figures`, below).
added to the Figure (see :ref:`saving_figures`, below). If you use a backend
other than the default "inline" backend, you will likely need to use an ipython
"magic" like ``%matplotlib notebook`` for the Matplotlib :ref:`notebook
<jupyter_notebooks_jupyterlab>` or ``%matplotlib widget`` for the `ipympl
<https://matplotlib.org/ipympl/>`_ backend.

.. figure:: /_static/FigureNotebook.png
:alt: Image of figure generated in Jupyter Notebook with notebook
backend, including a toolbar.
:width: 400

Screenshot of a Jupyter Notebook with an interactive figure generated via
the ``%matplotlib notebook`` magic. Users should also try the similar
`widget <https://matplotlib.org/ipympl/>`_ backend if using `JupyterLab
<https://jupyterlab.readthedocs.io/en/stable/>`_.


.. seealso::
:ref:`interactive_figures`.

Standalone scripts and interactive use
--------------------------------------

If the user is on a client with a windowing system, there are a number of
:ref:`Backends <what-is-a-backend>` that can be used to render the Figure to
the screen, usually using a Python Qt, Tk, or Wx toolkit, though there is a native
MacOS backend as well. These are typically chosen either in the user's
:ref:`matplotlibrc <customizing-with-matplotlibrc-files>`, or by calling
the screen, usually using a Python Qt, Tk, or Wx toolkit, or the native MacOS
backend. These are typically chosen either in the user's :ref:`matplotlibrc
<customizing-with-matplotlibrc-files>`, or by calling, for example,
``matplotlib.use('QtAgg')`` at the beginning of a session or script.

.. figure:: /_static/FigureQtAgg.png
:alt: Image of figure generated from a script via the QtAgg backend.
:width: 370

Screenshot of a Figure generated via a python script and shown using the
QtAgg backend.

When run from a script, or interactively (e.g. from an
`iPython shell <https://ipython.readthedocs.io/en/stable/>`_) the Figure
will not be shown until we call ``plt.show()``. The Figure will appear in
Expand All @@ -64,6 +98,9 @@ Note that if you are on a client that does not have access to a windowing
system, the Figure will fallback to being drawn using the "Agg" backend, and
cannot be viewed, though it can be :ref:`saved <saving_figures>`.

.. seealso::
:ref:`interactive_figures`.

.. _creating_figures:

Creating Figures
Expand Down
10 changes: 9 additions & 1 deletion doc/users/explain/interactive.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.. currentmodule:: matplotlib

.. _mpl-shell:
.. _interactive_figures:

===================
Interactive figures
Expand All @@ -12,6 +13,10 @@ When working with data, interactivity can be invaluable. The pan/zoom and
mouse-location tools built into the Matplotlib GUI windows are often sufficient, but
you can also use the event system to build customized data exploration tools.

.. seealso::
:ref:`figure_explanation`.


Matplotlib ships with :ref:`backends <what-is-a-backend>` binding to
several GUI toolkits (Qt, Tk, Wx, GTK, macOS, JavaScript) and third party
packages provide bindings to `kivy
Expand Down Expand Up @@ -42,7 +47,9 @@ collected. `.Figure`\s can be closed and deregistered from `.pyplot` individuall
`.pyplot.close`; all open `.Figure`\s can be closed via ``plt.close('all')``.


For more discussion of Matplotlib's event system and integrated event loops, please read:
.. seealso::

For more discussion of Matplotlib's event system and integrated event loops:

- :ref:`interactive_figures_and_eventloops`
- :ref:`event-handling-tutorial`
Expand Down Expand Up @@ -246,6 +253,7 @@ and your figures may not be responsive. Please consult the
documentation of your GUI toolkit for details.


.. _jupyter_notebooks_jupyterlab:

Jupyter Notebooks / JupyterLab
------------------------------
Expand Down
3 changes: 3 additions & 0 deletions doc/users/project/citing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ By version
.. START OF AUTOGENERATED
v3.7.0
.. image:: ../../_static/zenodo_cache/7637593.svg
:target: https://doi.org/10.5281/zenodo.7637593
v3.6.3
.. image:: ../../_static/zenodo_cache/7527665.svg
:target: https://doi.org/10.5281/zenodo.7527665
Expand Down
2 changes: 1 addition & 1 deletion doc/users/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Release notes
=============

.. include from another document so that it's easy to exclude this for releases
.. include:: release_notes_next.rst
.. .. include:: release_notes_next.rst
Version 3.7
Expand Down
18 changes: 16 additions & 2 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,22 @@
`SubplotParams`
Control the default spacing between subplots.
See :ref:`figure_explanation` for narrative on how figures are used in
Matplotlib.
Figures are typically created using pyplot methods `~.pyplot.figure`,
`~.pyplot.subplots`, and `~.pyplot.subplot_mosaic`.
.. plot::
:include-source:
fig, ax = plt.subplots(figsize=(2, 2), facecolor='lightskyblue',
layout='constrained')
fig.suptitle('Figure')
ax.set_title('Axes', loc='left', fontstyle='oblique', fontsize='medium')
Some situations call for directly instantiating a `~.figure.Figure` class,
usually inside an application of some sort (see :ref:`user_interfaces` for a
list of examples) . More information about Figures can be found at
:ref:`figure_explanation`.
"""

from contextlib import ExitStack
Expand Down
1 change: 1 addition & 0 deletions tools/cache_zenodo_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def _get_xdg_cache_dir():

if __name__ == "__main__":
data = {
"v3.7.0": "7637593",
"v3.6.3": "7527665",
"v3.6.2": "7275322",
"v3.6.1": "7162185",
Expand Down
12 changes: 11 additions & 1 deletion tutorials/introductory/quick_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@
fig, ax = plt.subplots() # Create a figure containing a single axes.
ax.plot([1, 2, 3, 4], [1, 4, 2, 3]) # Plot some data on the axes.

###############################################################################
# %%
#
# Note that to get this Figure to display, you may have to call ``plt.show()``,
# depending on your backend. For more details of Figures and backends, see
# :ref:`figure_explanation`.
#
# .. _figure_parts:
#
# Parts of a Figure
Expand All @@ -53,12 +58,17 @@
# fig = plt.figure() # an empty figure with no Axes
# fig, ax = plt.subplots() # a figure with a single Axes
# fig, axs = plt.subplots(2, 2) # a figure with a 2x2 grid of Axes
# # a figure with one axes on the left, and two on the right:
# fig, axs = plt.subplot_mosaic([['left', 'right-top'],
# ['left', 'right_bottom]])
#
# It is often convenient to create the Axes together with the Figure, but you
# can also manually add Axes later on. Note that many
# :doc:`Matplotlib backends </users/explain/backends>` support zooming and
# panning on figure windows.
#
# For more on Figures, see :ref:`figure_explanation`.
#
# :class:`~matplotlib.axes.Axes`
# ------------------------------
#
Expand Down

0 comments on commit 250cca9

Please sign in to comment.