forked from matplotlib/matplotlib.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyplot_tutorial.html
More file actions
587 lines (552 loc) · 49.5 KB
/
pyplot_tutorial.html
File metadata and controls
587 lines (552 loc) · 49.5 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Pyplot tutorial — Matplotlib 1.3.1 documentation</title>
<link rel="stylesheet" href="../_static/mpl.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '1.3.1',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Matplotlib 1.3.1 documentation"
href="../_static/opensearch.xml"/>
<link rel="top" title="Matplotlib 1.3.1 documentation" href="../index.html" />
<link rel="up" title="User’s Guide" href="index.html" />
<link rel="next" title="Interactive navigation" href="navigation_toolbar.html" />
<link rel="prev" title="Installing" href="installing.html" />
<link rel="canonical" href="https://matplotlib.org/2.0.2/users/pyplot_tutorial.html" />
</head>
<body>
<div id="unreleased-message"> You are reading an old version of the documentation (v1.3.1). For the latest version see <a href="/stable/">https://matplotlib.org/stable/</a> </div>
<!-- Piwik -->
<script type="text/javascript">
if ("matplotlib.sourceforge.net" == document.location.hostname ||
"matplotlib.sf.net" == document.location.hostname) {
var pkBaseURL = (("https:" == document.location.protocol) ? "https://apps.sourceforge.net/piwik/matplotlib/" : "http://apps.sourceforge.net/piwik/matplotlib/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>
<script type="text/javascript">
if ("matplotlib.sourceforge.net" == document.location.hostname ||
"matplotlib.sf.net" == document.location.hostname) {
piwik_action_name = '';
piwik_idsite = 1;
piwik_url = pkBaseURL + "piwik.php";
piwik_log(piwik_action_name, piwik_idsite, piwik_url);
document.write(unescape('%3Cobject%3E%3Cnoscript%3E%3Cp%3E%3Cimg src="http://apps.sourceforge.net/piwik/matplotlib/piwik.php?idsite=1" alt="piwik"/%3E%3C/p%3E%3C/noscript%3E%3C/object%3E'));
}
</script>
<!-- End Piwik Tag -->
<link rel="shortcut icon" href="_static/favicon.ico">
<!-- The "Fork me on github" ribbon -->
<img style="float: right; margin-bottom: -40px; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png" usemap="#ribbonmap"/>
<map name="ribbonmap">
<area shape="poly" coords="15,0,148,-1,148,135" href="https://github.com/matplotlib/matplotlib" title="Fork me on GitHub" />
</map>
<div style="background-color: white; text-align: left; padding: 10px 10px 15px 15px">
<a href="../index.html"><img src="../_static/logo2.png" border="0" alt="matplotlib"/></a>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="navigation_toolbar.html" title="Interactive navigation"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="installing.html" title="Installing"
accesskey="P">previous</a> |</li>
<li><a href="../index.html">home</a>| </li>
<li><a href="../examples/index.html">examples</a>| </li>
<li><a href="../gallery.html">gallery</a>| </li>
<li><a href="../api/pyplot_summary.html">pyplot</a>| </li>
<li><a href="../contents.html">docs</a> »</li>
<li><a href="index.html" accesskey="U">User’s Guide</a> »</li>
</ul>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<h3><a href="../contents.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Pyplot tutorial</a><ul>
<li><a class="reference internal" href="#controlling-line-properties">Controlling line properties</a></li>
<li><a class="reference internal" href="#working-with-multiple-figures-and-axes">Working with multiple figures and axes</a></li>
<li><a class="reference internal" href="#working-with-text">Working with text</a><ul>
<li><a class="reference internal" href="#using-mathematical-expressions-in-text">Using mathematical expressions in text</a></li>
<li><a class="reference internal" href="#annotating-text">Annotating text</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="installing.html"
title="previous chapter">Installing</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="navigation_toolbar.html"
title="next chapter">Interactive navigation</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/users/pyplot_tutorial.txt"
rel="nofollow">Show Source</a></li>
</ul>
<div id="searchbox" style="display: none">
<h3>Quick search</h3>
<form class="search" action="../search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="pyplot-tutorial">
<span id="id1"></span><h1>Pyplot tutorial<a class="headerlink" href="#pyplot-tutorial" title="Permalink to this headline">¶</a></h1>
<p><a class="reference internal" href="../api/pyplot_api.html#module-matplotlib.pyplot" title="matplotlib.pyplot"><tt class="xref py py-mod docutils literal"><span class="pre">matplotlib.pyplot</span></tt></a> is a collection of command style functions
that make matplotlib work like MATLAB.
Each <tt class="docutils literal"><span class="pre">pyplot</span></tt> function makes
some change to a figure: eg, create a figure, create a plotting area
in a figure, plot some lines in a plotting area, decorate the plot
with labels, etc.... <a class="reference internal" href="../api/pyplot_api.html#module-matplotlib.pyplot" title="matplotlib.pyplot"><tt class="xref py py-mod docutils literal"><span class="pre">matplotlib.pyplot</span></tt></a> is stateful, in that it
keeps track of the current figure and plotting area, and the plotting
functions are directed to the current axes</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="kn">as</span> <span class="nn">plt</span>
<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">])</span>
<span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s">'some numbers'</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<p>(<a class="reference external" href="../pyplots/pyplot_simple.py">Source code</a>, <a class="reference external" href="../pyplots/pyplot_simple.png">png</a>, <a class="reference external" href="../pyplots/pyplot_simple.hires.png">hires.png</a>, <a class="reference external" href="../pyplots/pyplot_simple.pdf">pdf</a>)</p>
<div class="figure">
<img alt="../_images/pyplot_simple.png" src="../_images/pyplot_simple.png" />
</div>
<p>You may be wondering why the x-axis ranges from 0-3 and the y-axis
from 1-4. If you provide a single list or array to the
<a class="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.plot" title="matplotlib.pyplot.plot"><tt class="xref py py-func docutils literal"><span class="pre">plot()</span></tt></a> command, matplotlib assumes it is a
sequence of y values, and automatically generates the x values for
you. Since python ranges start with 0, the default x vector has the
same length as y but starts with 0. Hence the x data are
<tt class="docutils literal"><span class="pre">[0,1,2,3]</span></tt>.</p>
<p><a class="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.plot" title="matplotlib.pyplot.plot"><tt class="xref py py-func docutils literal"><span class="pre">plot()</span></tt></a> is a versatile command, and will take
an arbitrary number of arguments. For example, to plot x versus y,
you can issue the command:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">9</span><span class="p">,</span><span class="mi">16</span><span class="p">])</span>
</pre></div>
</div>
<p>For every x, y pair of arguments, there is an optional third argument
which is the format string that indicates the color and line type of
the plot. The letters and symbols of the format string are from
MATLAB, and you concatenate a color string with a line style string.
The default format string is ‘b-‘, which is a solid blue line. For
example, to plot the above with red circles, you would issue</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="kn">as</span> <span class="nn">plt</span>
<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">],</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">4</span><span class="p">,</span><span class="mi">9</span><span class="p">,</span><span class="mi">16</span><span class="p">],</span> <span class="s">'ro'</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">axis</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">20</span><span class="p">])</span>
<span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<p>(<a class="reference external" href="../pyplots/pyplot_formatstr.py">Source code</a>, <a class="reference external" href="../pyplots/pyplot_formatstr.png">png</a>, <a class="reference external" href="../pyplots/pyplot_formatstr.hires.png">hires.png</a>, <a class="reference external" href="../pyplots/pyplot_formatstr.pdf">pdf</a>)</p>
<div class="figure">
<img alt="../_images/pyplot_formatstr.png" src="../_images/pyplot_formatstr.png" />
</div>
<p>See the <a class="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.plot" title="matplotlib.pyplot.plot"><tt class="xref py py-func docutils literal"><span class="pre">plot()</span></tt></a> documentation for a complete
list of line styles and format strings. The
<a class="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.axis" title="matplotlib.pyplot.axis"><tt class="xref py py-func docutils literal"><span class="pre">axis()</span></tt></a> command in the example above takes a
list of <tt class="docutils literal"><span class="pre">[xmin,</span> <span class="pre">xmax,</span> <span class="pre">ymin,</span> <span class="pre">ymax]</span></tt> and specifies the viewport of the
axes.</p>
<p>If matplotlib were limited to working with lists, it would be fairly
useless for numeric processing. Generally, you will use <a class="reference external" href="http://numpy.scipy.org">numpy</a> arrays. In fact, all sequences are
converted to numpy arrays internally. The example below illustrates a
plotting several lines with different format styles in one command
using arrays.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="kn">as</span> <span class="nn">plt</span>
<span class="c"># evenly sampled time at 200ms intervals</span>
<span class="n">t</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mf">0.</span><span class="p">,</span> <span class="mf">5.</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">)</span>
<span class="c"># red dashes, blue squares and green triangles</span>
<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="s">'r--'</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">t</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="s">'bs'</span><span class="p">,</span> <span class="n">t</span><span class="p">,</span> <span class="n">t</span><span class="o">**</span><span class="mi">3</span><span class="p">,</span> <span class="s">'g^'</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<p>(<a class="reference external" href="../pyplots/pyplot_three.py">Source code</a>, <a class="reference external" href="../pyplots/pyplot_three.png">png</a>, <a class="reference external" href="../pyplots/pyplot_three.hires.png">hires.png</a>, <a class="reference external" href="../pyplots/pyplot_three.pdf">pdf</a>)</p>
<div class="figure">
<img alt="../_images/pyplot_three.png" src="../_images/pyplot_three.png" />
</div>
<div class="section" id="controlling-line-properties">
<span id="id2"></span><h2>Controlling line properties<a class="headerlink" href="#controlling-line-properties" title="Permalink to this headline">¶</a></h2>
<p>Lines have many attributes that you can set: linewidth, dash style,
antialiased, etc; see <a class="reference internal" href="../api/artist_api.html#matplotlib.lines.Line2D" title="matplotlib.lines.Line2D"><tt class="xref py py-class docutils literal"><span class="pre">matplotlib.lines.Line2D</span></tt></a>. There are
several ways to set line properties</p>
<ul>
<li><p class="first">Use keyword args:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="mf">2.0</span><span class="p">)</span>
</pre></div>
</div>
</li>
<li><p class="first">Use the setter methods of the <tt class="docutils literal"><span class="pre">Line2D</span></tt> instance. <tt class="docutils literal"><span class="pre">plot</span></tt> returns a list
of lines; eg <tt class="docutils literal"><span class="pre">line1,</span> <span class="pre">line2</span> <span class="pre">=</span> <span class="pre">plot(x1,y1,x2,y2)</span></tt>. Below I have only
one line so it is a list of length 1. I use tuple unpacking in the
<tt class="docutils literal"><span class="pre">line,</span> <span class="pre">=</span> <span class="pre">plot(x,</span> <span class="pre">y,</span> <span class="pre">'o')</span></tt> to get the first element of the list:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">line</span><span class="p">,</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="s">'-'</span><span class="p">)</span>
<span class="n">line</span><span class="o">.</span><span class="n">set_antialiased</span><span class="p">(</span><span class="bp">False</span><span class="p">)</span> <span class="c"># turn off antialising</span>
</pre></div>
</div>
</li>
<li><p class="first">Use the <a class="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.setp" title="matplotlib.pyplot.setp"><tt class="xref py py-func docutils literal"><span class="pre">setp()</span></tt></a> command. The example below
uses a MATLAB-style command to set multiple properties
on a list of lines. <tt class="docutils literal"><span class="pre">setp</span></tt> works transparently with a list of objects
or a single object. You can either use python keyword arguments or
MATLAB-style string/value pairs:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">lines</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">x1</span><span class="p">,</span> <span class="n">y1</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">y2</span><span class="p">)</span>
<span class="c"># use keyword args</span>
<span class="n">plt</span><span class="o">.</span><span class="n">setp</span><span class="p">(</span><span class="n">lines</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s">'r'</span><span class="p">,</span> <span class="n">linewidth</span><span class="o">=</span><span class="mf">2.0</span><span class="p">)</span>
<span class="c"># or MATLAB style string value pairs</span>
<span class="n">plt</span><span class="o">.</span><span class="n">setp</span><span class="p">(</span><span class="n">lines</span><span class="p">,</span> <span class="s">'color'</span><span class="p">,</span> <span class="s">'r'</span><span class="p">,</span> <span class="s">'linewidth'</span><span class="p">,</span> <span class="mf">2.0</span><span class="p">)</span>
</pre></div>
</div>
</li>
</ul>
<p>Here are the available <a class="reference internal" href="../api/artist_api.html#matplotlib.lines.Line2D" title="matplotlib.lines.Line2D"><tt class="xref py py-class docutils literal"><span class="pre">Line2D</span></tt></a> properties.</p>
<table border="1" class="docutils">
<colgroup>
<col width="31%" />
<col width="69%" />
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">Property</th>
<th class="head">Value Type</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>alpha</td>
<td>float</td>
</tr>
<tr class="row-odd"><td>animated</td>
<td>[True | False]</td>
</tr>
<tr class="row-even"><td>antialiased or aa</td>
<td>[True | False]</td>
</tr>
<tr class="row-odd"><td>clip_box</td>
<td>a matplotlib.transform.Bbox instance</td>
</tr>
<tr class="row-even"><td>clip_on</td>
<td>[True | False]</td>
</tr>
<tr class="row-odd"><td>clip_path</td>
<td>a Path instance and a Transform instance, a Patch</td>
</tr>
<tr class="row-even"><td>color or c</td>
<td>any matplotlib color</td>
</tr>
<tr class="row-odd"><td>contains</td>
<td>the hit testing function</td>
</tr>
<tr class="row-even"><td>dash_capstyle</td>
<td>[‘butt’ | ‘round’ | ‘projecting’]</td>
</tr>
<tr class="row-odd"><td>dash_joinstyle</td>
<td>[‘miter’ | ‘round’ | ‘bevel’]</td>
</tr>
<tr class="row-even"><td>dashes</td>
<td>sequence of on/off ink in points</td>
</tr>
<tr class="row-odd"><td>data</td>
<td>(np.array xdata, np.array ydata)</td>
</tr>
<tr class="row-even"><td>figure</td>
<td>a matplotlib.figure.Figure instance</td>
</tr>
<tr class="row-odd"><td>label</td>
<td>any string</td>
</tr>
<tr class="row-even"><td>linestyle or ls</td>
<td>[ ‘-‘ | ‘–’ | ‘-.’ | ‘:’ | ‘steps’ | ...]</td>
</tr>
<tr class="row-odd"><td>linewidth or lw</td>
<td>float value in points</td>
</tr>
<tr class="row-even"><td>lod</td>
<td>[True | False]</td>
</tr>
<tr class="row-odd"><td>marker</td>
<td>[ ‘+’ | ‘,’ | ‘.’ | ‘1’ | ‘2’ | ‘3’ | ‘4’</td>
</tr>
<tr class="row-even"><td>markeredgecolor or mec</td>
<td>any matplotlib color</td>
</tr>
<tr class="row-odd"><td>markeredgewidth or mew</td>
<td>float value in points</td>
</tr>
<tr class="row-even"><td>markerfacecolor or mfc</td>
<td>any matplotlib color</td>
</tr>
<tr class="row-odd"><td>markersize or ms</td>
<td>float</td>
</tr>
<tr class="row-even"><td>markevery</td>
<td>None | integer | (startind, stride)</td>
</tr>
<tr class="row-odd"><td>picker</td>
<td>used in interactive line selection</td>
</tr>
<tr class="row-even"><td>pickradius</td>
<td>the line pick selection radius</td>
</tr>
<tr class="row-odd"><td>solid_capstyle</td>
<td>[‘butt’ | ‘round’ | ‘projecting’]</td>
</tr>
<tr class="row-even"><td>solid_joinstyle</td>
<td>[‘miter’ | ‘round’ | ‘bevel’]</td>
</tr>
<tr class="row-odd"><td>transform</td>
<td>a matplotlib.transforms.Transform instance</td>
</tr>
<tr class="row-even"><td>visible</td>
<td>[True | False]</td>
</tr>
<tr class="row-odd"><td>xdata</td>
<td>np.array</td>
</tr>
<tr class="row-even"><td>ydata</td>
<td>np.array</td>
</tr>
<tr class="row-odd"><td>zorder</td>
<td>any number</td>
</tr>
</tbody>
</table>
<p>To get a list of settable line properties, call the
<a class="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.setp" title="matplotlib.pyplot.setp"><tt class="xref py py-func docutils literal"><span class="pre">setp()</span></tt></a> function with a line or lines
as argument</p>
<div class="highlight-ipython"><div class="highlight"><pre><span class="gp">In [69]: </span><span class="n">lines</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
<span class="gp">In [70]: </span><span class="n">plt</span><span class="o">.</span><span class="n">setp</span><span class="p">(</span><span class="n">lines</span><span class="p">)</span>
<span class="go"> alpha: float</span>
<span class="go"> animated: [True | False]</span>
<span class="go"> antialiased or aa: [True | False]</span>
<span class="go"> ...snip</span>
</pre></div>
</div>
</div>
<div class="section" id="working-with-multiple-figures-and-axes">
<span id="multiple-figs-axes"></span><h2>Working with multiple figures and axes<a class="headerlink" href="#working-with-multiple-figures-and-axes" title="Permalink to this headline">¶</a></h2>
<p>MATLAB, and <a class="reference internal" href="../api/pyplot_api.html#module-matplotlib.pyplot" title="matplotlib.pyplot"><tt class="xref py py-mod docutils literal"><span class="pre">pyplot</span></tt></a>, have the concept of the current
figure and the current axes. All plotting commands apply to the
current axes. The function <a class="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.gca" title="matplotlib.pyplot.gca"><tt class="xref py py-func docutils literal"><span class="pre">gca()</span></tt></a> returns the
current axes (a <a class="reference internal" href="../api/axes_api.html#matplotlib.axes.Axes" title="matplotlib.axes.Axes"><tt class="xref py py-class docutils literal"><span class="pre">matplotlib.axes.Axes</span></tt></a> instance), and
<a class="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.gcf" title="matplotlib.pyplot.gcf"><tt class="xref py py-func docutils literal"><span class="pre">gcf()</span></tt></a> returns the current figure
(<a class="reference internal" href="../api/figure_api.html#matplotlib.figure.Figure" title="matplotlib.figure.Figure"><tt class="xref py py-class docutils literal"><span class="pre">matplotlib.figure.Figure</span></tt></a> instance). Normally, you don’t have
to worry about this, because it is all taken care of behind the
scenes. Below is a script to create two subplots.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="kn">as</span> <span class="nn">plt</span>
<span class="k">def</span> <span class="nf">f</span><span class="p">(</span><span class="n">t</span><span class="p">):</span>
<span class="k">return</span> <span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">t</span><span class="p">)</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="o">*</span><span class="n">t</span><span class="p">)</span>
<span class="n">t1</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">5.0</span><span class="p">,</span> <span class="mf">0.1</span><span class="p">)</span>
<span class="n">t2</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">5.0</span><span class="p">,</span> <span class="mf">0.02</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">211</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">t1</span><span class="p">,</span> <span class="n">f</span><span class="p">(</span><span class="n">t1</span><span class="p">),</span> <span class="s">'bo'</span><span class="p">,</span> <span class="n">t2</span><span class="p">,</span> <span class="n">f</span><span class="p">(</span><span class="n">t2</span><span class="p">),</span> <span class="s">'k'</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">212</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">t2</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="o">*</span><span class="n">t2</span><span class="p">),</span> <span class="s">'r--'</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<p>(<a class="reference external" href="../pyplots/pyplot_two_subplots.py">Source code</a>, <a class="reference external" href="../pyplots/pyplot_two_subplots.png">png</a>, <a class="reference external" href="../pyplots/pyplot_two_subplots.hires.png">hires.png</a>, <a class="reference external" href="../pyplots/pyplot_two_subplots.pdf">pdf</a>)</p>
<div class="figure">
<img alt="../_images/pyplot_two_subplots.png" src="../_images/pyplot_two_subplots.png" />
</div>
<p>The <a class="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.figure" title="matplotlib.pyplot.figure"><tt class="xref py py-func docutils literal"><span class="pre">figure()</span></tt></a> command here is optional because
<tt class="docutils literal"><span class="pre">figure(1)</span></tt> will be created by default, just as a <tt class="docutils literal"><span class="pre">subplot(111)</span></tt>
will be created by default if you don’t manually specify an axes. The
<a class="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.subplot" title="matplotlib.pyplot.subplot"><tt class="xref py py-func docutils literal"><span class="pre">subplot()</span></tt></a> command specifies <tt class="docutils literal"><span class="pre">numrows,</span>
<span class="pre">numcols,</span> <span class="pre">fignum</span></tt> where <tt class="docutils literal"><span class="pre">fignum</span></tt> ranges from 1 to
<tt class="docutils literal"><span class="pre">numrows*numcols</span></tt>. The commas in the <tt class="docutils literal"><span class="pre">subplot</span></tt> command are
optional if <tt class="docutils literal"><span class="pre">numrows*numcols<10</span></tt>. So <tt class="docutils literal"><span class="pre">subplot(211)</span></tt> is identical
to <tt class="docutils literal"><span class="pre">subplot(2,1,1)</span></tt>. You can create an arbitrary number of subplots
and axes. If you want to place an axes manually, ie, not on a
rectangular grid, use the <a class="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.axes" title="matplotlib.pyplot.axes"><tt class="xref py py-func docutils literal"><span class="pre">axes()</span></tt></a> command,
which allows you to specify the location as <tt class="docutils literal"><span class="pre">axes([left,</span> <span class="pre">bottom,</span>
<span class="pre">width,</span> <span class="pre">height])</span></tt> where all values are in fractional (0 to 1)
coordinates. See <a class="reference internal" href="../examples/pylab_examples/axes_demo.html#pylab-examples-axes-demo"><em>pylab_examples example code: axes_demo.py</em></a> for an example of
placing axes manually and <a class="reference internal" href="../examples/pylab_examples/line_styles.html#pylab-examples-line-styles"><em>pylab_examples example code: line_styles.py</em></a> for an
example with lots-o-subplots.</p>
<p>You can create multiple figures by using multiple
<a class="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.figure" title="matplotlib.pyplot.figure"><tt class="xref py py-func docutils literal"><span class="pre">figure()</span></tt></a> calls with an increasing figure
number. Of course, each figure can contain as many axes and subplots
as your heart desires:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="kn">as</span> <span class="nn">plt</span>
<span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="c"># the first figure</span>
<span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">211</span><span class="p">)</span> <span class="c"># the first subplot in the first figure</span>
<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">])</span>
<span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">212</span><span class="p">)</span> <span class="c"># the second subplot in the first figure</span>
<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">([</span><span class="mi">4</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">6</span><span class="p">])</span>
<span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="c"># a second figure</span>
<span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">([</span><span class="mi">4</span><span class="p">,</span><span class="mi">5</span><span class="p">,</span><span class="mi">6</span><span class="p">])</span> <span class="c"># creates a subplot(111) by default</span>
<span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="c"># figure 1 current; subplot(212) still current</span>
<span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">211</span><span class="p">)</span> <span class="c"># make subplot(211) in figure1 current</span>
<span class="n">plt</span><span class="o">.</span><span class="n">title</span><span class="p">(</span><span class="s">'Easy as 1,2,3'</span><span class="p">)</span> <span class="c"># subplot 211 title</span>
</pre></div>
</div>
<p>You can clear the current figure with <a class="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.clf" title="matplotlib.pyplot.clf"><tt class="xref py py-func docutils literal"><span class="pre">clf()</span></tt></a>
and the current axes with <a class="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.cla" title="matplotlib.pyplot.cla"><tt class="xref py py-func docutils literal"><span class="pre">cla()</span></tt></a>. If you find
this statefulness, annoying, don’t despair, this is just a thin
stateful wrapper around an object oriented API, which you can use
instead (see <a class="reference internal" href="artists.html#artist-tutorial"><em>Artist tutorial</em></a>)</p>
<p>If you are making a long sequence of figures, you need to be aware of one
more thing: the memory required for a figure is not completely
released until the figure is explicitly closed with
<a class="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.close" title="matplotlib.pyplot.close"><tt class="xref py py-func docutils literal"><span class="pre">close()</span></tt></a>. Deleting all references to the
figure, and/or using the window manager to kill the window in which
the figure appears on the screen, is not enough, because pyplot
maintains internal references until <a class="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.close" title="matplotlib.pyplot.close"><tt class="xref py py-func docutils literal"><span class="pre">close()</span></tt></a>
is called.</p>
</div>
<div class="section" id="working-with-text">
<span id="id3"></span><h2>Working with text<a class="headerlink" href="#working-with-text" title="Permalink to this headline">¶</a></h2>
<p>The <a class="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.text" title="matplotlib.pyplot.text"><tt class="xref py py-func docutils literal"><span class="pre">text()</span></tt></a> command can be used to add text in
an arbitrary location, and the <a class="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.xlabel" title="matplotlib.pyplot.xlabel"><tt class="xref py py-func docutils literal"><span class="pre">xlabel()</span></tt></a>,
<a class="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.ylabel" title="matplotlib.pyplot.ylabel"><tt class="xref py py-func docutils literal"><span class="pre">ylabel()</span></tt></a> and <a class="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.title" title="matplotlib.pyplot.title"><tt class="xref py py-func docutils literal"><span class="pre">title()</span></tt></a>
are used to add text in the indicated locations (see <a class="reference internal" href="text_intro.html#text-intro"><em>Text introduction</em></a>
for a more detailed example)</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="kn">as</span> <span class="nn">plt</span>
<span class="n">mu</span><span class="p">,</span> <span class="n">sigma</span> <span class="o">=</span> <span class="mi">100</span><span class="p">,</span> <span class="mi">15</span>
<span class="n">x</span> <span class="o">=</span> <span class="n">mu</span> <span class="o">+</span> <span class="n">sigma</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">randn</span><span class="p">(</span><span class="mi">10000</span><span class="p">)</span>
<span class="c"># the histogram of the data</span>
<span class="n">n</span><span class="p">,</span> <span class="n">bins</span><span class="p">,</span> <span class="n">patches</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">hist</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">50</span><span class="p">,</span> <span class="n">normed</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">facecolor</span><span class="o">=</span><span class="s">'g'</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mf">0.75</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s">'Smarts'</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">ylabel</span><span class="p">(</span><span class="s">'Probability'</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">title</span><span class="p">(</span><span class="s">'Histogram of IQ'</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="mi">60</span><span class="p">,</span> <span class="o">.</span><span class="mo">025</span><span class="p">,</span> <span class="s">r'$\mu=100,\ \sigma=15$'</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">axis</span><span class="p">([</span><span class="mi">40</span><span class="p">,</span> <span class="mi">160</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mf">0.03</span><span class="p">])</span>
<span class="n">plt</span><span class="o">.</span><span class="n">grid</span><span class="p">(</span><span class="bp">True</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<p>(<a class="reference external" href="../pyplots/pyplot_text.py">Source code</a>, <a class="reference external" href="../pyplots/pyplot_text.png">png</a>, <a class="reference external" href="../pyplots/pyplot_text.hires.png">hires.png</a>, <a class="reference external" href="../pyplots/pyplot_text.pdf">pdf</a>)</p>
<div class="figure">
<img alt="../_images/pyplot_text.png" src="../_images/pyplot_text.png" />
</div>
<p>All of the <a class="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.text" title="matplotlib.pyplot.text"><tt class="xref py py-func docutils literal"><span class="pre">text()</span></tt></a> commands return an
<a class="reference internal" href="../api/artist_api.html#matplotlib.text.Text" title="matplotlib.text.Text"><tt class="xref py py-class docutils literal"><span class="pre">matplotlib.text.Text</span></tt></a> instance. Just as with with lines
above, you can customize the properties by passing keyword arguments
into the text functions or using <a class="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.setp" title="matplotlib.pyplot.setp"><tt class="xref py py-func docutils literal"><span class="pre">setp()</span></tt></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">t</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">xlabel</span><span class="p">(</span><span class="s">'my data'</span><span class="p">,</span> <span class="n">fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s">'red'</span><span class="p">)</span>
</pre></div>
</div>
<p>These properties are covered in more detail in <a class="reference internal" href="text_props.html#text-properties"><em>Text properties and layout</em></a>.</p>
<div class="section" id="using-mathematical-expressions-in-text">
<h3>Using mathematical expressions in text<a class="headerlink" href="#using-mathematical-expressions-in-text" title="Permalink to this headline">¶</a></h3>
<p>matplotlib accepts TeX equation expressions in any text expression.
For example to write the expression <img src="../_images/mathmpl/math-4cd9a23707.png" style="position: relative; bottom: -7px"/> in the title,
you can write a TeX expression surrounded by dollar signs:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">plt</span><span class="o">.</span><span class="n">title</span><span class="p">(</span><span class="s">r'$\sigma_i=15$'</span><span class="p">)</span>
</pre></div>
</div>
<p>The <tt class="docutils literal"><span class="pre">r</span></tt> preceding the title string is important – it signifies
that the string is a <em>raw</em> string and not to treat backslashes and
python escapes. matplotlib has a built-in TeX expression parser and
layout engine, and ships its own math fonts – for details see
<a class="reference internal" href="mathtext.html#mathtext-tutorial"><em>Writing mathematical expressions</em></a>. Thus you can use mathematical text across platforms
without requiring a TeX installation. For those who have LaTeX and
dvipng installed, you can also use LaTeX to format your text and
incorporate the output directly into your display figures or saved
postscript – see <a class="reference internal" href="usetex.html#usetex-tutorial"><em>Text rendering With LaTeX</em></a>.</p>
</div>
<div class="section" id="annotating-text">
<h3>Annotating text<a class="headerlink" href="#annotating-text" title="Permalink to this headline">¶</a></h3>
<p>The uses of the basic <a class="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.text" title="matplotlib.pyplot.text"><tt class="xref py py-func docutils literal"><span class="pre">text()</span></tt></a> command above
place text at an arbitrary position on the Axes. A common use case of
text is to annotate some feature of the plot, and the
<a class="reference internal" href="../api/pyplot_api.html#matplotlib.pyplot.annotate" title="matplotlib.pyplot.annotate"><tt class="xref py py-func docutils literal"><span class="pre">annotate()</span></tt></a> method provides helper
functionality to make annotations easy. In an annotation, there are
two points to consider: the location being annotated represented by
the argument <tt class="docutils literal"><span class="pre">xy</span></tt> and the location of the text <tt class="docutils literal"><span class="pre">xytext</span></tt>. Both of
these arguments are <tt class="docutils literal"><span class="pre">(x,y)</span></tt> tuples.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="kn">as</span> <span class="nn">plt</span>
<span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">111</span><span class="p">)</span>
<span class="n">t</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">5.0</span><span class="p">,</span> <span class="mf">0.01</span><span class="p">)</span>
<span class="n">s</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="mi">2</span><span class="o">*</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span><span class="o">*</span><span class="n">t</span><span class="p">)</span>
<span class="n">line</span><span class="p">,</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">plot</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">s</span><span class="p">,</span> <span class="n">lw</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">annotate</span><span class="p">(</span><span class="s">'local max'</span><span class="p">,</span> <span class="n">xy</span><span class="o">=</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">xytext</span><span class="o">=</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mf">1.5</span><span class="p">),</span>
<span class="n">arrowprops</span><span class="o">=</span><span class="nb">dict</span><span class="p">(</span><span class="n">facecolor</span><span class="o">=</span><span class="s">'black'</span><span class="p">,</span> <span class="n">shrink</span><span class="o">=</span><span class="mf">0.05</span><span class="p">),</span>
<span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">ylim</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span><span class="mi">2</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">show</span><span class="p">()</span>
</pre></div>
</div>
<p>(<a class="reference external" href="../pyplots/pyplot_annotate.py">Source code</a>, <a class="reference external" href="../pyplots/pyplot_annotate.png">png</a>, <a class="reference external" href="../pyplots/pyplot_annotate.hires.png">hires.png</a>, <a class="reference external" href="../pyplots/pyplot_annotate.pdf">pdf</a>)</p>
<div class="figure">
<img alt="../_images/pyplot_annotate.png" src="../_images/pyplot_annotate.png" />
</div>
<p>In this basic example, both the <tt class="docutils literal"><span class="pre">xy</span></tt> (arrow tip) and <tt class="docutils literal"><span class="pre">xytext</span></tt>
locations (text location) are in data coordinates. There are a
variety of other coordinate systems one can choose – see
<a class="reference internal" href="annotations_intro.html#annotations-tutorial"><em>Annotating text</em></a> and <a class="reference internal" href="annotations_guide.html#plotting-guide-annotation"><em>Annotating Axes</em></a> for
details. More examples can be found in
<a class="reference internal" href="../examples/pylab_examples/annotation_demo.html#pylab-examples-annotation-demo"><em>pylab_examples example code: annotation_demo.py</em></a>.</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="navigation_toolbar.html" title="Interactive navigation"
>next</a> |</li>
<li class="right" >
<a href="installing.html" title="Installing"
>previous</a> |</li>
<li><a href="../index.html">home</a>| </li>
<li><a href="../examples/index.html">examples</a>| </li>
<li><a href="../gallery.html">gallery</a>| </li>
<li><a href="../api/pyplot_summary.html">pyplot</a>| </li>
<li><a href="../contents.html">docs</a> »</li>
<li><a href="index.html" >User’s Guide</a> »</li>
</ul>
</div>
<div class="footer">
© Copyright 2002 - 2012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom and the matplotlib development team; 2012 - 2013 The matplotlib development team.
Last updated on Oct 10, 2013.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2b2.
</div>
</body>
</html>