@@ -7,10 +7,11 @@ Pyplot tutorial
7
7
:mod: `matplotlib.pyplot ` is a collection of command style functions
8
8
that make matplotlib work like MATLAB.
9
9
Each ``pyplot `` function makes
10
- some change to a figure: e.g., create a figure, create a plotting area
11
- in a figure, plot some lines in a plotting area, decorate the plot
12
- with labels, etc.... :mod: `matplotlib.pyplot ` is stateful, in that it
13
- keeps track of the current figure and plotting area, and the plotting
10
+ some change to a figure: e.g., creates a figure, creates a plotting area
11
+ in a figure, plots some lines in a plotting area, decorates the plot
12
+ with labels, etc. In :mod: `matplotlib.pyplot ` various states are preserved
13
+ across function calls, so that it keeps track of things like
14
+ the current figure and plotting area, and the plotting
14
15
functions are directed to the current axes (please note that "axes" here
15
16
and in most places in the documentation refers to the *axes *
16
17
`part of a figure <http://matplotlib.org/faq/usage_faq.html#parts-of-a-figure >`__
@@ -31,7 +32,7 @@ same length as y but starts with 0. Hence the x data are
31
32
an arbitrary number of arguments. For example, to plot x versus y,
32
33
you can issue the command::
33
34
34
- plt.plot([1,2,3, 4], [1,4,9, 16])
35
+ plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
35
36
36
37
For every x, y pair of arguments, there is an optional third argument
37
38
which is the format string that indicates the color and line type of
@@ -73,10 +74,11 @@ several ways to set line properties
73
74
plt.plot(x, y, linewidth=2.0)
74
75
75
76
76
- * Use the setter methods of the ``Line2D `` instance. ``plot `` returns a list
77
- of lines; e.g., ``line1, line2 = plot(x1,y1,x2,y2) ``. Below I have only
78
- one line so it is a list of length 1. I use tuple unpacking in the
79
- ``line, = plot(x, y, 'o') `` to get the first element of the list::
77
+ * Use the setter methods of a ``Line2D `` instance. ``plot `` returns a list
78
+ of ``Line2D `` objects; e.g., ``line1, line2 = plot(x1, y1, x2, y2) ``. In the code
79
+ below we will suppose that we have only
80
+ one line so that the list returned is of length 1. We use tuple unpacking with
81
+ ``line, `` to get the first element of that list::
80
82
81
83
line, = plt.plot(x, y, '-')
82
84
line.set_antialiased(False) # turn off antialising
@@ -139,7 +141,7 @@ as argument
139
141
140
142
.. sourcecode :: ipython
141
143
142
- In [69]: lines = plt.plot([1,2, 3])
144
+ In [69]: lines = plt.plot([1, 2, 3])
143
145
144
146
In [70]: plt.setp(lines)
145
147
alpha: float
@@ -172,14 +174,14 @@ will be created by default if you don't manually specify any axes. The
172
174
numcols, fignum `` where ``fignum `` ranges from 1 to
173
175
``numrows*numcols ``. The commas in the ``subplot `` command are
174
176
optional if ``numrows*numcols<10 ``. So ``subplot(211) `` is identical
175
- to ``subplot(2,1, 1) ``. You can create an arbitrary number of subplots
177
+ to ``subplot(2, 1, 1) ``. You can create an arbitrary number of subplots
176
178
and axes. If you want to place an axes manually, i.e., not on a
177
179
rectangular grid, use the :func: `~matplotlib.pyplot.axes ` command,
178
180
which allows you to specify the location as ``axes([left, bottom,
179
181
width, height]) `` where all values are in fractional (0 to 1)
180
182
coordinates. See :ref: `pylab_examples-axes_demo ` for an example of
181
183
placing axes manually and :ref: `pylab_examples-subplots_demo ` for an
182
- example with lots-o- subplots.
184
+ example with lots of subplots.
183
185
184
186
185
187
You can create multiple figures by using multiple
@@ -190,25 +192,26 @@ as your heart desires::
190
192
import matplotlib.pyplot as plt
191
193
plt.figure(1) # the first figure
192
194
plt.subplot(211) # the first subplot in the first figure
193
- plt.plot([1,2, 3])
195
+ plt.plot([1, 2, 3])
194
196
plt.subplot(212) # the second subplot in the first figure
195
- plt.plot([4,5, 6])
197
+ plt.plot([4, 5, 6])
196
198
197
199
198
200
plt.figure(2) # a second figure
199
- plt.plot([4,5, 6]) # creates a subplot(111) by default
201
+ plt.plot([4, 5, 6]) # creates a subplot(111) by default
200
202
201
203
plt.figure(1) # figure 1 current; subplot(212) still current
202
204
plt.subplot(211) # make subplot(211) in figure1 current
203
- plt.title('Easy as 1,2, 3') # subplot 211 title
205
+ plt.title('Easy as 1, 2, 3') # subplot 211 title
204
206
205
207
You can clear the current figure with :func: `~matplotlib.pyplot.clf `
206
208
and the current axes with :func: `~matplotlib.pyplot.cla `. If you find
207
- this statefulness, annoying, don't despair, this is just a thin
209
+ it annoying that states (specifically the current image, figure and axes)
210
+ are being maintained for you behind the scenes, don't despair: this is just a thin
208
211
stateful wrapper around an object oriented API, which you can use
209
212
instead (see :ref: `artist-tutorial `)
210
213
211
- If you are making a long sequence of figures, you need to be aware of one
214
+ If you are making lots of figures, you need to be aware of one
212
215
more thing: the memory required for a figure is not completely
213
216
released until the figure is explicitly closed with
214
217
:func: `~matplotlib.pyplot.close `. Deleting all references to the
@@ -266,7 +269,7 @@ Annotating text
266
269
---------------
267
270
268
271
The uses of the basic :func: `~matplotlib.pyplot.text ` command above
269
- place text at an arbitrary position on the Axes. A common use case of
272
+ place text at an arbitrary position on the Axes. A common use for
270
273
text is to annotate some feature of the plot, and the
271
274
:func: `~matplotlib.pyplot.annotate ` method provides helper
272
275
functionality to make annotations easy. In an annotation, there are
0 commit comments