File: api_overview.rst

package info (click to toggle)
matplotlib 3.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 77,480 kB
  • sloc: python: 124,525; cpp: 58,549; ansic: 29,599; objc: 2,348; makefile: 148; sh: 57
file content (56 lines) | stat: -rw-r--r-- 1,964 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
API Overview
============

Below we describe several common approaches to plotting with Matplotlib.

.. contents::

The pyplot API
--------------

`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.

`.pyplot` is mainly intended for interactive plots and simple cases of
programmatic plot generation.

Further reading:

- The `matplotlib.pyplot` function reference
- :doc:`/tutorials/introductory/pyplot`
- :ref:`Pyplot examples <pyplots_examples>`

The object-oriented API
-----------------------

At its core, Matbplotlib is object-oriented. We recommend directly working
with the objects, if you need more control and customization of your plots.

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

Further reading:

- `matplotlib.axes.Axes` and `matplotlib.figure.Figure` for an overview of
  plotting functions.
- Most of the :ref:`examples <examples-index>` use the object-oriented approach
  (except for the pyplot section)
- The list of :doc:`matplotlib modules </api/index>`.


The pylab API (disapproved)
---------------------------

.. warning::
   Since heavily importing into the global namespace may result in unexpected
   behavior, the use of pylab is strongly discouraged. Use `matplotlib.pyplot`
   instead.

`matplotlib.pylab` is a module that includes `matplotlib.pyplot`, `numpy`
and some additional functions within a single namespace. It's original puropse
was to mimic a MATLAB-like way of working by importing all functions into the
global namespace. This is considered bad style nowadays.