|
1 |
| -API Overview |
2 |
| -============ |
| 1 | +API |
| 2 | +=== |
3 | 3 |
|
4 |
| -.. toctree:: |
5 |
| - :hidden: |
| 4 | +For recent changes, see :doc:`api_changes`. |
6 | 5 |
|
7 |
| - api_changes |
| 6 | +Much of the library can be accessed by creating :doc:`Figure <figure_api>` |
| 7 | +and :doc:`Axes <axes_api>` objects and accessing methods on them. |
8 | 8 |
|
9 |
| -.. contents:: :local: |
| 9 | + - :doc:`figure_api`: axes creation, figure-level artists |
| 10 | + - :doc:`axes_api`: most plotting methods, axes labels, access to |
| 11 | + axis styling, etc. |
10 | 12 |
|
11 |
| -See also the :doc:`api_changes`. |
| 13 | +Simple example: note how the ``ax`` object has the `.axes.Axes.plot` method |
| 14 | +that is used to create the line plot. |
| 15 | + |
| 16 | +.. plot:: |
| 17 | + :include-source: |
| 18 | + :align: center |
12 | 19 |
|
13 |
| -Usage patterns |
14 |
| --------------- |
| 20 | + import matplotlib.pyplot as plt |
| 21 | + import numpy as np |
15 | 22 |
|
16 |
| -Below we describe several common approaches to plotting with Matplotlib. |
| 23 | + x = np.arange(0, 4, 0.1) |
| 24 | + y = np.sin(x*np.pi) |
17 | 25 |
|
18 |
| -The pyplot API |
19 |
| -^^^^^^^^^^^^^^ |
| 26 | + fig, ax = plt.subplots(figsize=(3,2), constrained_layout=True) |
| 27 | + ax.plot(x, y) |
| 28 | + ax.set_xlabel('t [s]') |
| 29 | + ax.set_ylabel('S [V]') |
| 30 | + fig.suptitle('Sine wave') |
20 | 31 |
|
21 |
| -`matplotlib.pyplot` is a collection of command style functions that make |
22 |
| -Matplotlib work like MATLAB. Each pyplot function makes some change to a |
23 |
| -figure: e.g., creates a figure, creates a plotting area in a figure, plots |
24 |
| -some lines in a plotting area, decorates the plot with labels, etc. |
25 |
| - |
26 |
| -`.pyplot` is mainly intended for interactive plots and simple cases of |
27 |
| -programmatic plot generation. |
28 |
| - |
29 |
| -Further reading: |
30 |
| - |
31 |
| -- The `matplotlib.pyplot` function reference |
32 |
| -- :doc:`/tutorials/introductory/pyplot` |
33 |
| -- :ref:`Pyplot examples <pyplots_examples>` |
34 |
| - |
35 |
| -.. _api-index: |
36 |
| - |
37 |
| -The object-oriented API |
38 |
| -^^^^^^^^^^^^^^^^^^^^^^^ |
39 |
| - |
40 |
| -At its core, Matplotlib is object-oriented. We recommend directly working |
41 |
| -with the objects, if you need more control and customization of your plots. |
42 |
| - |
43 |
| -In many cases you will create a `.Figure` and one or more |
44 |
| -`~matplotlib.axes.Axes` using `.pyplot.subplots` and from then on only work |
45 |
| -on these objects. However, it's also possible to create `.Figure`\ s |
46 |
| -explicitly (e.g. when including them in GUI applications). |
47 |
| - |
48 |
| -Further reading: |
49 |
| - |
50 |
| -- `matplotlib.axes.Axes` and `matplotlib.figure.Figure` for an overview of |
51 |
| - plotting functions. |
52 |
| -- Most of the :ref:`examples <examples-index>` use the object-oriented approach |
53 |
| - (except for the pyplot section) |
54 |
| - |
55 |
| -The pylab API (disapproved) |
56 |
| -^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
57 |
| - |
58 |
| -.. automodule:: pylab |
59 |
| - :no-members: |
60 | 32 |
|
61 | 33 | Modules
|
62 | 34 | -------
|
63 | 35 |
|
64 |
| -Matplotlib consists of the following submodules: |
| 36 | +Alphabetical list of all submodules: |
65 | 37 |
|
66 | 38 | .. toctree::
|
67 | 39 | :maxdepth: 1
|
@@ -147,3 +119,52 @@ Matplotlib. The following toolkits are included:
|
147 | 119 | toolkits/axes_grid1.rst
|
148 | 120 | toolkits/axisartist.rst
|
149 | 121 | toolkits/axes_grid.rst
|
| 122 | + |
| 123 | + |
| 124 | +Usage patterns |
| 125 | +-------------- |
| 126 | + |
| 127 | +Below we describe several common approaches to plotting with Matplotlib. |
| 128 | + |
| 129 | +The pyplot API |
| 130 | +^^^^^^^^^^^^^^ |
| 131 | + |
| 132 | +`matplotlib.pyplot` is a collection of command style functions that make |
| 133 | +Matplotlib work like MATLAB. Each pyplot function makes some change to a |
| 134 | +figure: e.g., creates a figure, creates a plotting area in a figure, plots |
| 135 | +some lines in a plotting area, decorates the plot with labels, etc. |
| 136 | + |
| 137 | +`.pyplot` is mainly intended for interactive plots and simple cases of |
| 138 | +programmatic plot generation. |
| 139 | + |
| 140 | +Further reading: |
| 141 | + |
| 142 | +- The `matplotlib.pyplot` function reference |
| 143 | +- :doc:`/tutorials/introductory/pyplot` |
| 144 | +- :ref:`Pyplot examples <pyplots_examples>` |
| 145 | + |
| 146 | +.. _api-index: |
| 147 | + |
| 148 | +The object-oriented API |
| 149 | +^^^^^^^^^^^^^^^^^^^^^^^ |
| 150 | + |
| 151 | +At its core, Matplotlib is object-oriented. We recommend directly working |
| 152 | +with the objects, if you need more control and customization of your plots. |
| 153 | + |
| 154 | +In many cases you will create a `.Figure` and one or more |
| 155 | +`~matplotlib.axes.Axes` using `.pyplot.subplots` and from then on only work |
| 156 | +on these objects. However, it's also possible to create `.Figure`\ s |
| 157 | +explicitly (e.g. when including them in GUI applications). |
| 158 | + |
| 159 | +Further reading: |
| 160 | + |
| 161 | +- `matplotlib.axes.Axes` and `matplotlib.figure.Figure` for an overview of |
| 162 | + plotting functions. |
| 163 | +- Most of the :ref:`examples <examples-index>` use the object-oriented approach |
| 164 | + (except for the pyplot section) |
| 165 | + |
| 166 | +The pylab API (disapproved) |
| 167 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 168 | + |
| 169 | +.. automodule:: pylab |
| 170 | + :no-members: |
0 commit comments