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