|
| 1 | +--- |
| 2 | +sidebarDepth: 3 |
| 3 | +sidebar: auto |
| 4 | +--- |
| 5 | + |
| 6 | +# API Overview |
| 7 | + |
| 8 | +- Usage patterns |
| 9 | + - The pyplot API |
| 10 | + - The object-oriented API |
| 11 | + - The pylab API (disapproved) |
| 12 | +- Modules |
| 13 | +- Toolkits |
| 14 | + |
| 15 | +See also the [API Changes](https://matplotlib.org/api/api_changes.html). |
| 16 | + |
| 17 | +## Usage patterns |
| 18 | + |
| 19 | +Below we describe several common approaches to plotting with Matplotlib. |
| 20 | + |
| 21 | +### The pyplot API |
| 22 | + |
| 23 | +[matplotlib.pyplot](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.html#module-matplotlib.pyplot) is a collection of command style functions that make Matplotlib work like MATLAB. Each pyplot function makes some change to a figure: e.g., creates a figure, creates a plotting area in a figure, plots some lines in a plotting area, decorates the plot with labels, etc. |
| 24 | + |
| 25 | +[pyplot](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.html#module-matplotlib.pyplot) is mainly intended for interactive plots and simple cases of programmatic plot generation. |
| 26 | + |
| 27 | +Further reading: |
| 28 | + |
| 29 | +- The [matplotlib.pyplot](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.html#module-matplotlib.pyplot) function reference |
| 30 | +- [Pyplot tutorial](https://matplotlib.org/tutorials/introductory/pyplot.html) |
| 31 | +- [Pyplot examples](https://matplotlib.org/gallery/index.html#pyplots-examples) |
| 32 | + |
| 33 | +### The object-oriented API |
| 34 | + |
| 35 | +At its core, Matplotlib is object-oriented. We recommend directly working with the objects, if you need more control and customization of your plots. |
| 36 | + |
| 37 | +In many cases you will create a [Figure](https://matplotlib.org/api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure) and one or more [Axes](https://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes) using [pyplot.subplots](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.subplots.html#matplotlib.pyplot.subplots) and from then on only work on these objects. However, it's also possible to create [Figure](https://matplotlib.org/api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure)s explicitly (e.g. when including them in GUI applications). |
| 38 | + |
| 39 | +Further reading: |
| 40 | + |
| 41 | +- [matplotlib.axes.Axes](https://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes) and [matplotlib.figure.Figure](https://matplotlib.org/api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure) for an overview of plotting functions. |
| 42 | +- Most of the [examples](https://matplotlib.org/gallery/index.html#examples-index) use the object-oriented approach (except for the pyplot section) |
| 43 | + |
| 44 | +### The pylab API (disapproved) |
| 45 | + |
| 46 | +::: danger Warning |
| 47 | + |
| 48 | +Since heavily importing into the global namespace may result in unexpected behavior, the use of pylab is strongly discouraged. Use [matplotlib.pyplot](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.html#module-matplotlib.pyplot) instead. |
| 49 | + |
| 50 | +::: |
| 51 | + |
| 52 | +pylab is a module that includes [matplotlib.pyplot](https://matplotlib.org/api/_as_gen/matplotlib.pyplot.html#module-matplotlib.pyplot), [numpy](https://docs.scipy.org/doc/numpy/reference/index.html#module-numpy) and some additional functions within a single namespace. Its original purpose was to mimic a MATLAB-like way of working by importing all functions into the global namespace. This is considered bad style nowadays. |
| 53 | + |
| 54 | +## Modules |
| 55 | + |
| 56 | +Matplotlib consists of the following submodules: |
| 57 | + |
| 58 | +- matplotlib |
| 59 | +- matplotlib.afm |
| 60 | +- matplotlib.animation |
| 61 | +- matplotlib.artist |
| 62 | +- matplotlib.axes |
| 63 | +- matplotlib.axis |
| 64 | +- matplotlib.backend_bases |
| 65 | +- matplotlib.backend_managers |
| 66 | +- matplotlib.backend_tools |
| 67 | +- matplotlib.backends |
| 68 | +- matplotlib.blocking_input |
| 69 | +- matplotlib.category |
| 70 | +- matplotlib.cbook |
| 71 | +- matplotlib.cm |
| 72 | +- matplotlib.collections |
| 73 | +- matplotlib.colorbar |
| 74 | +- matplotlib.colors |
| 75 | +- matplotlib.container |
| 76 | +- matplotlib.contour |
| 77 | +- matplotlib.dates |
| 78 | +- matplotlib.dviread |
| 79 | +- matplotlib.figure |
| 80 | +- matplotlib.font_manager |
| 81 | +- matplotlib.fontconfig_pattern |
| 82 | +- matplotlib.gridspec |
| 83 | +- matplotlib.image |
| 84 | +- matplotlib.legend |
| 85 | +- matplotlib.legend_handler |
| 86 | +- matplotlib.lines |
| 87 | +- matplotlib.markers |
| 88 | +- matplotlib.mathtext |
| 89 | +- matplotlib.mlab |
| 90 | +- matplotlib.offsetbox |
| 91 | +- matplotlib.patches |
| 92 | +- matplotlib.path |
| 93 | +- matplotlib.patheffects |
| 94 | +- matplotlib.pyplot |
| 95 | +- matplotlib.projections |
| 96 | +- matplotlib.projections.polar |
| 97 | +- matplotlib.rcsetup |
| 98 | +- matplotlib.sankey |
| 99 | +- matplotlib.scale |
| 100 | +- matplotlib.spines |
| 101 | +- matplotlib.style |
| 102 | +- matplotlib.table |
| 103 | +- matplotlib.testing |
| 104 | +- matplotlib.text |
| 105 | +- matplotlib.textpath |
| 106 | +- matplotlib.ticker |
| 107 | +- matplotlib.tight_layout |
| 108 | +- matplotlib.transforms |
| 109 | +- matplotlib.tri |
| 110 | +- matplotlib.type1font |
| 111 | +- matplotlib.units |
| 112 | +- matplotlib.widgets |
| 113 | + |
| 114 | +## Toolkits |
| 115 | + |
| 116 | +[Toolkits](https://matplotlib.org/api/toolkits/index.html#toolkits-index) are collections of application-specific functions that extend Matplotlib. The following toolkits are included: |
| 117 | + |
| 118 | +- Toolkits |
| 119 | +- mplot3d API |
| 120 | +- Matplotlib axes_grid1 Toolkit |
| 121 | +- Matplotlib axisartist Toolkit |
| 122 | +- Matplotlib axes_grid Toolkit |
0 commit comments