@@ -17,41 +17,34 @@ General Concepts
17
17
new users. However, most of matplotlib can be understood with a fairly
18
18
simple conceptual framework and knowledge of a few important points.
19
19
20
- All plotting is done by *axes *. In addition to the plots,
21
- the axes objects are responsible for other components that handle axis
22
- labeling, ticks, title, and plot legends. A *figure * is the container
23
- for one or more axes objects.
24
-
25
- Everything in matplotlib is organized in a hierarchy. At the top
26
- of the hierarchy is the matplotlib state-machine environment. This
27
- environment is responsible for managing the figures and axes
28
- that have been created and modified by you. The behavior of the matplotlib
29
- environment is similar to MATLAB and therefore should be most familiar to
30
- users with MATLAB experience.
31
-
32
- There are two interfaces to this environment: :mod: `pylab ` and
33
- :mod: `matplotlib.pyplot `. Through one of these two interfaces, the user
34
- creates *figures *. These figures, in turn, create one or more *axes *.
35
- These axes are then used for any plotting requested by you. Depending
36
- on how you use matplotlib, these figures and axes can be created explicitly
37
- by you through the interface::
20
+ Plotting requires action on a range of levels, from the most general
21
+ (e.g., 'contour this 2-D array') to the most specific (e.g., 'color
22
+ this screen pixel red'). The purpose of a plotting package is to assist
23
+ you in visualizing your data as easily as possible, with all the necessary
24
+ control -- that is, by using relatively high-level commands most of
25
+ the time, and still have the ability to use the low-level commands when
26
+ needed.
27
+
28
+ Therefore, everything in matplotlib is organized in a hierarchy. At the top
29
+ of the hierarchy is the matplotlib "state-machine environment" which is
30
+ provided by the :mod: `matplotlib.pyplot ` module. At this level, simple
31
+ functions are used to add plot elements (lines, images, text, etc.) to
32
+ the current axes in the current figure.
38
33
39
- import matplotlib.pyplot as plt
34
+ .. note ::
35
+ Pyplot's state-machine environment behaves similarly to MATLAB and
36
+ should be most familiar to users with MATLAB experience.
40
37
41
- fig = plt.figure()
42
- ax = fig.gca()
43
- ax.plot(range(10), range(10))
44
- ax.set_title("Simple Plot")
45
- plt.show()
46
-
47
- or implicitly by the state-machine environment::
48
-
49
- import matplotlib.pyplot as plt
50
-
51
- plt.plot(range(10), range(10))
52
- plt.title("Simple Plot")
53
- plt.show()
38
+ The next level down in the hierarchy is the first level of the object-oriented
39
+ interface, in which pyplot is used only for a few functions such as figure
40
+ creation, and the user explicitly creates and keeps track of the figure
41
+ and axes objects. At this level, the user uses pyplot to create figures,
42
+ and through those figures, one or more axes objects can be created. These
43
+ axes objects are then used for most plotting actions.
54
44
45
+ For even more control -- which is essential for things like embedding
46
+ matplotlib plots in GUI applications -- the pyplot level may be dropped
47
+ completely, leaving a purely object-oriented approach.
55
48
56
49
.. _pylab :
57
50
@@ -62,17 +55,23 @@ Matplotlib is the whole package; :mod:`pylab` is a module in matplotlib
62
55
that gets installed alongside :mod: `matplotlib `; and :mod: `matplotlib.pyplot `
63
56
is a module in matplotlib.
64
57
65
- Pyplot provides a state-machine interface to the underlying plotting
66
- library in matplotlib.
67
- For example, calling a plotting function from pyplot will
68
- automatically create the necessary figure and axes to achieve
69
- the desired plot. Setting a title through pyplot will automatically
70
- set the title to the current axes object.
58
+ Pyplot provides the state-machine interface to the underlying plotting
59
+ library in matplotlib. This means that figures and axes are implicitly
60
+ and automatically created to achieve the desired plot. For example,
61
+ calling ``plot `` from pyplot will automatically create the necessary
62
+ figure and axes to achieve the desired plot. Setting a title will
63
+ then automatically set that title to the current axes object::
64
+
65
+ import matplotlib.pyplot as plt
66
+
67
+ plt.plot(range(10), range(10))
68
+ plt.title("Simple Plot")
69
+ plt.show()
71
70
72
71
Pylab combines the pyplot functionality (for plotting) with the numpy
73
72
functionality (for mathematics and for working with arrays)
74
73
in a single namespace, making that namespace
75
- (or environment) more MATLAB-like.
74
+ (or environment) even more MATLAB-like.
76
75
For example, one can call the `sin ` and `cos ` functions just like
77
76
you could in MATLAB, as well as having all the features of pyplot.
78
77
@@ -117,8 +116,8 @@ plt.plot, plt.show, etc. So, a simple example in this style would be::
117
116
plt.show()
118
117
119
118
Note that this example used pyplot's state-machine to
120
- automatically create a figure and an axes. For full control of
121
- your plots and more advanced usage, use the pyplot interface
119
+ automatically and implicitly create a figure and an axes. For full
120
+ control of your plots and more advanced usage, use the pyplot interface
122
121
for creating figures, and then use the object methods for the rest::
123
122
124
123
import matplotlib.pyplot as plt
@@ -143,7 +142,7 @@ So, why all the extra typing as one moves away from the pure
143
142
MATLAB-style? For very simple things like this example, the only
144
143
advantage is academic: the wordier styles are more explicit, more
145
144
clear as to where things come from and what is going on. For more
146
- complicated applications, this explicitness and clarity become
145
+ complicated applications, this explicitness and clarity becomes
147
146
increasingly valuable, and the richer and more complete object-oriented
148
147
interface will likely make the program easier to write and maintain.
149
148
0 commit comments