Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e272b5c

Browse files
committed
Restructure interface section of API Reference index page
- switch to Axes interface / pyplot interface terminology (#26388) - Reduce the interface description to very compact two-sentence descriptions and refer to the interface page for everything else. The focus here is to point the users to relevant API resources for the respective interfaces, not to discuss these interfaces in detail. The latter is the task of https://matplotlib.org/devdocs/users/explain/figure/api_interfaces.html and I will add some missing pieces there in a follow-up PR. Co-authored-by: hannah <[email protected]>
1 parent c12be12 commit e272b5c

File tree

2 files changed

+25
-31
lines changed

2 files changed

+25
-31
lines changed

doc/api/index.rst

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,47 +36,41 @@ methods on them to plot data, add axis labels and a figure title.
3636
Usage patterns
3737
--------------
3838

39-
Below we describe several common approaches to plotting with Matplotlib. See
40-
:ref:`api_interfaces` for an explanation of the trade-offs between the supported user
41-
APIs.
39+
Matplotlib provides two different interfaces:
4240

41+
- **Axes interface**: create a `.Figure` and one or more `~.axes.Axes` objects
42+
(typically using `.pyplot.subplots`), then *explicitly* use methods on these objects
43+
to add data, configure limits, set labels etc.
44+
- **pyplot interface**: consists of functions in the `.pyplot` module. Figure and Axes
45+
are manipulated through these functions and are only *implicitly* present in the
46+
background.
4347

44-
The explicit API
45-
^^^^^^^^^^^^^^^^
48+
See :ref:`api_interfaces` for a more detailed description of both and their recommended
49+
use cases.
4650

47-
At its core, Matplotlib is an object-oriented library. We recommend directly
48-
working with the objects if you need more control and customization of your
49-
plots.
51+
.. grid:: 1 1 2 2
52+
:padding: 0 0 1 1
5053

51-
In many cases you will create a `.Figure` and one or more
52-
`~matplotlib.axes.Axes` using `.pyplot.subplots` and from then on only work
53-
on these objects. However, it's also possible to create `.Figure`\ s
54-
explicitly (e.g. when including them in GUI applications).
54+
.. grid-item-card::
5555

56-
Further reading:
56+
**Axes interface** (object-based, explicit)
57+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5758

58-
- `matplotlib.axes.Axes` and `matplotlib.figure.Figure` for an overview of
59-
plotting functions.
60-
- Most of the :ref:`examples <examples-index>` use the object-oriented approach
61-
(except for the pyplot section)
59+
API:
6260

61+
- `~.pyplot.subplots`: create Figure and Axes
62+
- :doc:`Axes </api/axes_api>` add data, limits, labels etc.
63+
- :doc:`Figure <figure_api>` for figure-level methods
6364

64-
The implicit API
65-
^^^^^^^^^^^^^^^^
65+
.. grid-item-card::
6666

67-
`matplotlib.pyplot` is a collection of functions that make
68-
Matplotlib work like MATLAB. Each pyplot function makes some change to a
69-
figure: e.g., creates a figure, creates a plotting area in a figure, plots
70-
some lines in a plotting area, decorates the plot with labels, etc.
67+
**pyplot interface** (function-based, implicit)
68+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7169

72-
`.pyplot` is mainly intended for interactive plots and simple cases of
73-
programmatic plot generation.
70+
API:
7471

75-
Further reading:
72+
- `matplotlib.pyplot`
7673

77-
- The `matplotlib.pyplot` function reference
78-
- :ref:`pyplot_tutorial`
79-
- :ref:`Pyplot examples <pyplots_examples>`
8074

8175
.. _api-index:
8276

lib/matplotlib/pylab.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
`pylab` is a historic interface and its use is strongly discouraged. The equivalent
3-
replacement is `matplotlib.pyplot`. See :ref:` api_interfaces` for a full overview
3+
replacement is `matplotlib.pyplot`. See :ref:`api_interfaces` for a full overview
44
of Matplotlib interfaces.
55
66
`pylab` was designed to support a MATLAB-like way of working with all plotting related
@@ -14,7 +14,7 @@
1414
`numpy.fft`, `numpy.linalg`, and `numpy.random`, and some additional functions into
1515
the global namespace.
1616
17-
Such a pattern is nowadays considered bad practice, as it clutters the global
17+
Such a pattern is considered bad practice in modern python, as it clutters the global
1818
namespace. Even more severely, in the case of `pylab`, this will overwrite some
1919
builtin functions (e.g. the builtin `sum` will be replaced by `numpy.sum`), which
2020
can lead to unexpected behavior.

0 commit comments

Comments
 (0)