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

Skip to content

Commit 49b2728

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 49b2728

File tree

2 files changed

+27
-65
lines changed

2 files changed

+27
-65
lines changed

doc/api/index.rst

Lines changed: 25 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,44 @@
11
API Reference
22
=============
33

4-
When using the library you will typically create
5-
:doc:`Figure <figure_api>` and :doc:`Axes <axes_api>` objects and
6-
call their methods to add content and modify the appearance.
4+
Matplotlib interfaces
5+
---------------------
76

8-
- :mod:`matplotlib.figure`: axes creation, figure-level content
9-
- :mod:`matplotlib.axes`: most plotting methods, Axes labels, access to axis
10-
styling, etc.
7+
Matplotlib provides two different interfaces:
118

12-
Example: We create a Figure ``fig`` and Axes ``ax``. Then we call
13-
methods on them to plot data, add axis labels and a figure title.
9+
- **Axes interface**: create a `.Figure` and one or more `~.axes.Axes` objects
10+
(typically using `.pyplot.subplots`), then *explicitly* use methods on these objects
11+
to add data, configure limits, set labels etc.
12+
- **pyplot interface**: consists of functions in the `.pyplot` module. Figure and Axes
13+
are manipulated through these functions and are only *implicitly* present in the
14+
background.
1415

15-
.. plot::
16-
:include-source:
17-
:align: center
16+
See :ref:`api_interfaces` for a more detailed description of both and their recommended
17+
use cases.
1818

19-
import matplotlib.pyplot as plt
20-
import numpy as np
19+
.. grid:: 1 1 2 2
20+
:padding: 0 0 1 1
2121

22-
x = np.arange(0, 4, 0.05)
23-
y = np.sin(x*np.pi)
22+
.. grid-item-card::
2423

25-
fig, ax = plt.subplots(figsize=(3,2), constrained_layout=True)
26-
ax.plot(x, y)
27-
ax.set_xlabel('t [s]')
28-
ax.set_ylabel('S [V]')
29-
ax.set_title('Sine wave')
30-
fig.set_facecolor('lightsteelblue')
24+
**Axes interface** (object-based, explicit)
25+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3126

27+
API:
3228

29+
- `~.pyplot.subplots`: create Figure and Axes
30+
- :mod:`~matplotlib.axes`: add data, limits, labels etc.
31+
- `.Figure`: for figure-level methods
3332

34-
.. _usage_patterns:
33+
.. grid-item-card::
3534

36-
Usage patterns
37-
--------------
35+
**pyplot interface** (function-based, implicit)
36+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3837

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.
38+
API:
4239

40+
- `matplotlib.pyplot`
4341

44-
The explicit API
45-
^^^^^^^^^^^^^^^^
46-
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.
50-
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).
55-
56-
Further reading:
57-
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)
62-
63-
64-
The implicit API
65-
^^^^^^^^^^^^^^^^
66-
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.
71-
72-
`.pyplot` is mainly intended for interactive plots and simple cases of
73-
programmatic plot generation.
74-
75-
Further reading:
76-
77-
- The `matplotlib.pyplot` function reference
78-
- :ref:`pyplot_tutorial`
79-
- :ref:`Pyplot examples <pyplots_examples>`
8042

8143
.. _api-index:
8244

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)