-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPyplot tutorial — Matplotlib 2.0.0 documentation.html
802 lines (718 loc) · 67.4 KB
/
Pyplot tutorial — Matplotlib 2.0.0 documentation.html
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
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0043)http://matplotlib.org/users/pyplot_tutorial -->
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Pyplot tutorial — Matplotlib 2.0.0 documentation</title>
<link rel="stylesheet" href="./Pyplot tutorial — Matplotlib 2.0.0 documentation_files/mpl.css" type="text/css">
<link rel="stylesheet" href="./Pyplot tutorial — Matplotlib 2.0.0 documentation_files/pygments.css" type="text/css">
<script async="" src="./Pyplot tutorial — Matplotlib 2.0.0 documentation_files/analytics.js.download"></script><script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '2.0.0',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="./Pyplot tutorial — Matplotlib 2.0.0 documentation_files/jquery.js.download"></script>
<script type="text/javascript" src="./Pyplot tutorial — Matplotlib 2.0.0 documentation_files/underscore.js.download"></script>
<script type="text/javascript" src="./Pyplot tutorial — Matplotlib 2.0.0 documentation_files/doctools.js.download"></script>
<link rel="search" type="application/opensearchdescription+xml" title="Search within Matplotlib 2.0.0 documentation" href="http://matplotlib.org/_static/opensearch.xml">
<link rel="shortcut icon" href="http://matplotlib.org/_static/favicon.ico">
<link rel="index" title="Index" href="http://matplotlib.org/genindex.html">
<link rel="search" title="Search" href="http://matplotlib.org/search.html">
<link rel="top" title="Matplotlib 2.0.0 documentation" href="http://matplotlib.org/index.html">
<link rel="up" title="Tutorials" href="http://matplotlib.org/users/tutorials.html">
<link rel="next" title="Image tutorial" href="http://matplotlib.org/users/image_tutorial.html">
<link rel="prev" title="Tutorials" href="http://matplotlib.org/users/tutorials.html">
</head>
<body>
<!-- The "Fork me on github" ribbon -->
<img style="float: right; margin-bottom: -40px; top: 0; right: 0; border: 0;" src="./Pyplot tutorial — Matplotlib 2.0.0 documentation_files/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="http://matplotlib.org/index.html"><img src="./Pyplot tutorial — Matplotlib 2.0.0 documentation_files/logo2.svg" width="540px" border="0" alt="matplotlib"></a>
</div>
<div class="related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="http://matplotlib.org/genindex.html" title="General Index" accesskey="I">index</a></li>
<li class="right">
<a href="http://matplotlib.org/py-modindex.html" title="Python Module Index">modules</a> |</li>
<li class="right">
<a href="http://matplotlib.org/users/image_tutorial.html" title="Image tutorial" accesskey="N">next</a> |</li>
<li class="right">
<a href="http://matplotlib.org/users/tutorials.html" title="Tutorials" accesskey="P">previous</a> |</li>
<li><a href="http://matplotlib.org/index.html">home</a>| </li>
<li><a href="http://matplotlib.org/examples/index.html">examples</a>| </li>
<li><a href="http://matplotlib.org/gallery.html">gallery</a>| </li>
<li><a href="http://matplotlib.org/api/pyplot_summary.html">pyplot</a>| </li>
<li><a href="http://matplotlib.org/contents.html">docs</a> »</li>
<li><a href="http://matplotlib.org/users/index.html">User’s Guide</a> »</li>
<li><a href="http://matplotlib.org/users/tutorials.html" accesskey="U">Tutorials</a> »</li>
</ul>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<a href="http://depsy.org/package/python/matplotlib">
<img src="./Pyplot tutorial — Matplotlib 2.0.0 documentation_files/badge.svg">
</a>
<br>
Travis-CI: <a href="https://travis-ci.org/matplotlib/matplotlib">
<img src="./Pyplot tutorial — Matplotlib 2.0.0 documentation_files/matplotlib.svg">
</a>
<br>
<h3><a href="http://matplotlib.org/contents.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="http://matplotlib.org/users/pyplot_tutorial#">Pyplot tutorial</a><ul>
<li><a class="reference internal" href="http://matplotlib.org/users/pyplot_tutorial#controlling-line-properties">Controlling line properties</a></li>
<li><a class="reference internal" href="http://matplotlib.org/users/pyplot_tutorial#working-with-multiple-figures-and-axes">Working with multiple figures and axes</a></li>
<li><a class="reference internal" href="http://matplotlib.org/users/pyplot_tutorial#working-with-text">Working with text</a><ul>
<li><a class="reference internal" href="http://matplotlib.org/users/pyplot_tutorial#using-mathematical-expressions-in-text">Using mathematical expressions in text</a></li>
<li><a class="reference internal" href="http://matplotlib.org/users/pyplot_tutorial#annotating-text">Annotating text</a></li>
</ul>
</li>
<li><a class="reference internal" href="http://matplotlib.org/users/pyplot_tutorial#logarithmic-and-other-nonlinear-axis">Logarithmic and other nonlinear axis</a></li>
</ul>
</li>
</ul>
<div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="http://matplotlib.org/contents.html">Documentation overview</a><ul>
<li><a href="http://matplotlib.org/users/index.html">User’s Guide</a><ul>
<li><a href="http://matplotlib.org/users/tutorials.html">Tutorials</a><ul>
<li>Previous: <a href="http://matplotlib.org/users/tutorials.html" title="previous chapter">Tutorials</a></li>
<li>Next: <a href="http://matplotlib.org/users/image_tutorial.html" title="next chapter">Image tutorial</a></li>
</ul></li>
</ul></li>
</ul></li>
</ul>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="http://matplotlib.org/_sources/users/pyplot_tutorial.rst.txt" rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" role="search">
<h3>Quick search</h3>
<form class="search" action="http://matplotlib.org/search.html" method="get">
<div><input type="text" name="q"></div>
<div><input type="submit" value="Go"></div>
<input type="hidden" name="check_keywords" value="yes">
<input type="hidden" name="area" value="default">
</form>
</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="http://matplotlib.org/users/pyplot_tutorial#pyplot-tutorial" title="Permalink to this headline">¶</a></h1>
<p><a class="reference internal" href="http://matplotlib.org/api/pyplot_api.html#module-matplotlib.pyplot" title="matplotlib.pyplot"><code class="xref py py-mod docutils literal"><span class="pre">matplotlib.pyplot</span></code></a> is a collection of command style functions
that make matplotlib work like MATLAB.
Each <code class="docutils literal"><span class="pre">pyplot</span></code> 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. In <a class="reference internal" href="http://matplotlib.org/api/pyplot_api.html#module-matplotlib.pyplot" title="matplotlib.pyplot"><code class="xref py py-mod docutils literal"><span class="pre">matplotlib.pyplot</span></code></a> various states are preserved
across function calls, so that it keeps track of things like
the current figure and plotting area, and the plotting
functions are directed to the current axes (please note that “axes” here
and in most places in the documentation refers to the <em>axes</em>
<a class="reference external" href="http://matplotlib.org/faq/usage_faq.html#parts-of-a-figure">part of a figure</a>
and not the strict mathematical term for more than one axis).</p>
<div class="highlight-python"><div class="highlight"><pre><span></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">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="s1">'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="http://matplotlib.org/mpl_examples/pyplots/pyplot_simple.py">Source code</a>, <a class="reference external" href="http://matplotlib.org/mpl_examples/pyplots/pyplot_simple.png">png</a>, <a class="reference external" href="http://matplotlib.org/mpl_examples/pyplots/pyplot_simple.pdf">pdf</a>)</p>
<div class="figure">
<img alt="../_images/pyplot_simple.png" src="./Pyplot tutorial — Matplotlib 2.0.0 documentation_files/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="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.plot" title="matplotlib.pyplot.plot"><code class="xref py py-func docutils literal"><span class="pre">plot()</span></code></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
<code class="docutils literal"><span class="pre">[0,1,2,3]</span></code>.</p>
<p><a class="reference internal" href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.plot" title="matplotlib.pyplot.plot"><code class="xref py py-func docutils literal"><span class="pre">plot()</span></code></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-default"><div class="highlight"><pre><span></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>
</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></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">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="s1">'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="http://matplotlib.org/mpl_examples/pyplots/pyplot_formatstr.py">Source code</a>, <a class="reference external" href="http://matplotlib.org/mpl_examples/pyplots/pyplot_formatstr.png">png</a>, <a class="reference external" href="http://matplotlib.org/mpl_examples/pyplots/pyplot_formatstr.pdf">pdf</a>)</p>
<div class="figure">
<img alt="../_images/pyplot_formatstr.png" src="./Pyplot tutorial — Matplotlib 2.0.0 documentation_files/pyplot_formatstr.png">
</div>
<p>See the <a class="reference internal" href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.plot" title="matplotlib.pyplot.plot"><code class="xref py py-func docutils literal"><span class="pre">plot()</span></code></a> documentation for a complete
list of line styles and format strings. The
<a class="reference internal" href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.axis" title="matplotlib.pyplot.axis"><code class="xref py py-func docutils literal"><span class="pre">axis()</span></code></a> command in the example above takes a
list of <code class="docutils literal"><span class="pre">[xmin,</span> <span class="pre">xmax,</span> <span class="pre">ymin,</span> <span class="pre">ymax]</span></code> 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://www.numpy.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></span><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="c1"># 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="c1"># 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="s1">'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="s1">'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="s1">'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="http://matplotlib.org/mpl_examples/pyplots/pyplot_three.py">Source code</a>, <a class="reference external" href="http://matplotlib.org/mpl_examples/pyplots/pyplot_three.png">png</a>, <a class="reference external" href="http://matplotlib.org/mpl_examples/pyplots/pyplot_three.pdf">pdf</a>)</p>
<div class="figure">
<img alt="../_images/pyplot_three.png" src="./Pyplot tutorial — Matplotlib 2.0.0 documentation_files/pyplot_three.png">
</div>
<div class="section" id="controlling-line-properties">
<span id="id2"></span><h2>Controlling line properties<a class="headerlink" href="http://matplotlib.org/users/pyplot_tutorial#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="http://matplotlib.org/api/lines_api.html#matplotlib.lines.Line2D" title="matplotlib.lines.Line2D"><code class="xref py py-class docutils literal"><span class="pre">matplotlib.lines.Line2D</span></code></a>. There are
several ways to set line properties</p>
<ul>
<li><p class="first">Use keyword args:</p>
<div class="highlight-default"><div class="highlight"><pre><span></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="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 a <code class="docutils literal"><span class="pre">Line2D</span></code> instance. <code class="docutils literal"><span class="pre">plot</span></code> returns a list
of <code class="docutils literal"><span class="pre">Line2D</span></code> objects; e.g., <code class="docutils literal"><span class="pre">line1,</span> <span class="pre">line2</span> <span class="pre">=</span> <span class="pre">plot(x1,</span> <span class="pre">y1,</span> <span class="pre">x2,</span> <span class="pre">y2)</span></code>. In the code
below we will suppose that we have only
one line so that the list returned is of length 1. We use tuple unpacking with
<code class="docutils literal"><span class="pre">line,</span></code> to get the first element of that list:</p>
<div class="highlight-default"><div class="highlight"><pre><span></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">x</span><span class="p">,</span> <span class="n">y</span><span class="p">,</span> <span class="s1">'-'</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="kc">False</span><span class="p">)</span> <span class="c1"># turn off antialising</span>
</pre></div>
</div>
</li>
<li><p class="first">Use the <a class="reference internal" href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.setp" title="matplotlib.pyplot.setp"><code class="xref py py-func docutils literal"><span class="pre">setp()</span></code></a> command. The example below
uses a MATLAB-style command to set multiple properties
on a list of lines. <code class="docutils literal"><span class="pre">setp</span></code> 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-default"><div class="highlight"><pre><span></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="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="c1"># 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="s1">'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="c1"># 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="s1">'color'</span><span class="p">,</span> <span class="s1">'r'</span><span class="p">,</span> <span class="s1">'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="http://matplotlib.org/api/lines_api.html#matplotlib.lines.Line2D" title="matplotlib.lines.Line2D"><code class="xref py py-class docutils literal"><span class="pre">Line2D</span></code></a> properties.</p>
<table border="1" class="docutils">
<colgroup>
<col width="24%">
<col width="76%">
</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>[<code class="docutils literal"><span class="pre">'butt'</span></code> | <code class="docutils literal"><span class="pre">'round'</span></code> | <code class="docutils literal"><span class="pre">'projecting'</span></code>]</td>
</tr>
<tr class="row-odd"><td>dash_joinstyle</td>
<td>[<code class="docutils literal"><span class="pre">'miter'</span></code> | <code class="docutils literal"><span class="pre">'round'</span></code> | <code class="docutils literal"><span class="pre">'bevel'</span></code>]</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>[ <code class="docutils literal"><span class="pre">'-'</span></code> | <code class="docutils literal"><span class="pre">'--'</span></code> | <code class="docutils literal"><span class="pre">'-.'</span></code> | <code class="docutils literal"><span class="pre">':'</span></code> | <code class="docutils literal"><span class="pre">'steps'</span></code> | ...]</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>[ <code class="docutils literal"><span class="pre">'+'</span></code> | <code class="docutils literal"><span class="pre">','</span></code> | <code class="docutils literal"><span class="pre">'.'</span></code> | <code class="docutils literal"><span class="pre">'1'</span></code> | <code class="docutils literal"><span class="pre">'2'</span></code> | <code class="docutils literal"><span class="pre">'3'</span></code> | <code class="docutils literal"><span class="pre">'4'</span></code> ]</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>[<code class="docutils literal"><span class="pre">'butt'</span></code> | <code class="docutils literal"><span class="pre">'round'</span></code> | <code class="docutils literal"><span class="pre">'projecting'</span></code>]</td>
</tr>
<tr class="row-even"><td>solid_joinstyle</td>
<td>[<code class="docutils literal"><span class="pre">'miter'</span></code> | <code class="docutils literal"><span class="pre">'round'</span></code> | <code class="docutils literal"><span class="pre">'bevel'</span></code>]</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="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.setp" title="matplotlib.pyplot.setp"><code class="xref py py-func docutils literal"><span class="pre">setp()</span></code></a> function with a line or lines
as argument</p>
<div class="highlight-ipython"><div class="highlight"><pre><span></span><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="http://matplotlib.org/users/pyplot_tutorial#working-with-multiple-figures-and-axes" title="Permalink to this headline">¶</a></h2>
<p>MATLAB, and <a class="reference internal" href="http://matplotlib.org/api/pyplot_api.html#module-matplotlib.pyplot" title="matplotlib.pyplot"><code class="xref py py-mod docutils literal"><span class="pre">pyplot</span></code></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="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.gca" title="matplotlib.pyplot.gca"><code class="xref py py-func docutils literal"><span class="pre">gca()</span></code></a> returns the
current axes (a <a class="reference internal" href="http://matplotlib.org/api/axes_api.html#matplotlib.axes.Axes" title="matplotlib.axes.Axes"><code class="xref py py-class docutils literal"><span class="pre">matplotlib.axes.Axes</span></code></a> instance), and
<a class="reference internal" href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.gcf" title="matplotlib.pyplot.gcf"><code class="xref py py-func docutils literal"><span class="pre">gcf()</span></code></a> returns the current figure
(<a class="reference internal" href="http://matplotlib.org/api/figure_api.html#matplotlib.figure.Figure" title="matplotlib.figure.Figure"><code class="xref py py-class docutils literal"><span class="pre">matplotlib.figure.Figure</span></code></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></span><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="s1">'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="s1">'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="s1">'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="http://matplotlib.org/mpl_examples/pyplots/pyplot_two_subplots.py">Source code</a>, <a class="reference external" href="http://matplotlib.org/mpl_examples/pyplots/pyplot_two_subplots.png">png</a>, <a class="reference external" href="http://matplotlib.org/mpl_examples/pyplots/pyplot_two_subplots.pdf">pdf</a>)</p>
<div class="figure">
<img alt="../_images/pyplot_two_subplots.png" src="./Pyplot tutorial — Matplotlib 2.0.0 documentation_files/pyplot_two_subplots.png">
</div>
<p>The <a class="reference internal" href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.figure" title="matplotlib.pyplot.figure"><code class="xref py py-func docutils literal"><span class="pre">figure()</span></code></a> command here is optional because
<code class="docutils literal"><span class="pre">figure(1)</span></code> will be created by default, just as a <code class="docutils literal"><span class="pre">subplot(111)</span></code>
will be created by default if you don’t manually specify any axes. The
<a class="reference internal" href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.subplot" title="matplotlib.pyplot.subplot"><code class="xref py py-func docutils literal"><span class="pre">subplot()</span></code></a> command specifies <code class="docutils literal"><span class="pre">numrows,</span>
<span class="pre">numcols,</span> <span class="pre">fignum</span></code> where <code class="docutils literal"><span class="pre">fignum</span></code> ranges from 1 to
<code class="docutils literal"><span class="pre">numrows*numcols</span></code>. The commas in the <code class="docutils literal"><span class="pre">subplot</span></code> command are
optional if <code class="docutils literal"><span class="pre">numrows*numcols<10</span></code>. So <code class="docutils literal"><span class="pre">subplot(211)</span></code> is identical
to <code class="docutils literal"><span class="pre">subplot(2,</span> <span class="pre">1,</span> <span class="pre">1)</span></code>. You can create an arbitrary number of subplots
and axes. If you want to place an axes manually, i.e., not on a
rectangular grid, use the <a class="reference internal" href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.axes" title="matplotlib.pyplot.axes"><code class="xref py py-func docutils literal"><span class="pre">axes()</span></code></a> command,
which allows you to specify the location as <code class="docutils literal"><span class="pre">axes([left,</span> <span class="pre">bottom,</span>
<span class="pre">width,</span> <span class="pre">height])</span></code> where all values are in fractional (0 to 1)
coordinates. See <a class="reference internal" href="http://matplotlib.org/examples/pylab_examples/axes_demo.html#pylab-examples-axes-demo"><span class="std std-ref">pylab_examples example code: axes_demo.py</span></a> for an example of
placing axes manually and <a class="reference internal" href="http://matplotlib.org/examples/pylab_examples/subplots_demo.html#pylab-examples-subplots-demo"><span class="std std-ref">pylab_examples example code: subplots_demo.py</span></a> for an
example with lots of subplots.</p>
<p>You can create multiple figures by using multiple
<a class="reference internal" href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.figure" title="matplotlib.pyplot.figure"><code class="xref py py-func docutils literal"><span class="pre">figure()</span></code></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-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">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="c1"># 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="c1"># 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="c1"># 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="c1"># 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="c1"># 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="c1"># 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="c1"># 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="s1">'Easy as 1, 2, 3'</span><span class="p">)</span> <span class="c1"># subplot 211 title</span>
</pre></div>
</div>
<p>You can clear the current figure with <a class="reference internal" href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.clf" title="matplotlib.pyplot.clf"><code class="xref py py-func docutils literal"><span class="pre">clf()</span></code></a>
and the current axes with <a class="reference internal" href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.cla" title="matplotlib.pyplot.cla"><code class="xref py py-func docutils literal"><span class="pre">cla()</span></code></a>. If you find
it annoying that states (specifically the current image, figure and axes)
are being maintained for you behind the scenes, 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="http://matplotlib.org/users/artists.html#artist-tutorial"><span class="std std-ref">Artist tutorial</span></a>)</p>
<p>If you are making lots 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="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.close" title="matplotlib.pyplot.close"><code class="xref py py-func docutils literal"><span class="pre">close()</span></code></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="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.close" title="matplotlib.pyplot.close"><code class="xref py py-func docutils literal"><span class="pre">close()</span></code></a>
is called.</p>
</div>
<div class="section" id="working-with-text">
<span id="id3"></span><h2>Working with text<a class="headerlink" href="http://matplotlib.org/users/pyplot_tutorial#working-with-text" title="Permalink to this headline">¶</a></h2>
<p>The <a class="reference internal" href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.text" title="matplotlib.pyplot.text"><code class="xref py py-func docutils literal"><span class="pre">text()</span></code></a> command can be used to add text in
an arbitrary location, and the <a class="reference internal" href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.xlabel" title="matplotlib.pyplot.xlabel"><code class="xref py py-func docutils literal"><span class="pre">xlabel()</span></code></a>,
<a class="reference internal" href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.ylabel" title="matplotlib.pyplot.ylabel"><code class="xref py py-func docutils literal"><span class="pre">ylabel()</span></code></a> and <a class="reference internal" href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.title" title="matplotlib.pyplot.title"><code class="xref py py-func docutils literal"><span class="pre">title()</span></code></a>
are used to add text in the indicated locations (see <a class="reference internal" href="http://matplotlib.org/users/text_intro.html#text-intro"><span class="std std-ref">Text introduction</span></a>
for a more detailed example)</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><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="c1"># Fixing random state for reproducibility</span>
<span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">seed</span><span class="p">(</span><span class="mi">19680801</span><span class="p">)</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="c1"># 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="s1">'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="s1">'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="s1">'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="s1">'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="sa">r</span><span class="s1">'$\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="http://matplotlib.org/mpl_examples/pyplots/pyplot_text.py">Source code</a>, <a class="reference external" href="http://matplotlib.org/mpl_examples/pyplots/pyplot_text.png">png</a>, <a class="reference external" href="http://matplotlib.org/mpl_examples/pyplots/pyplot_text.pdf">pdf</a>)</p>
<div class="figure">
<img alt="../_images/pyplot_text.png" src="./Pyplot tutorial — Matplotlib 2.0.0 documentation_files/pyplot_text.png">
</div>
<p>All of the <a class="reference internal" href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.text" title="matplotlib.pyplot.text"><code class="xref py py-func docutils literal"><span class="pre">text()</span></code></a> commands return an
<a class="reference internal" href="http://matplotlib.org/api/text_api.html#matplotlib.text.Text" title="matplotlib.text.Text"><code class="xref py py-class docutils literal"><span class="pre">matplotlib.text.Text</span></code></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="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.setp" title="matplotlib.pyplot.setp"><code class="xref py py-func docutils literal"><span class="pre">setp()</span></code></a>:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><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="s1">'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="s1">'red'</span><span class="p">)</span>
</pre></div>
</div>
<p>These properties are covered in more detail in <a class="reference internal" href="http://matplotlib.org/users/text_props.html#text-properties"><span class="std std-ref">Text properties and layout</span></a>.</p>
<div class="section" id="using-mathematical-expressions-in-text">
<h3>Using mathematical expressions in text<a class="headerlink" href="http://matplotlib.org/users/pyplot_tutorial#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="./Pyplot tutorial — Matplotlib 2.0.0 documentation_files/math-4cd9a23707.png" style="position: relative; bottom: -6px"> in the title,
you can write a TeX expression surrounded by dollar signs:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="n">plt</span><span class="o">.</span><span class="n">title</span><span class="p">(</span><span class="sa">r</span><span class="s1">'$\sigma_i=15$'</span><span class="p">)</span>
</pre></div>
</div>
<p>The <code class="docutils literal"><span class="pre">r</span></code> preceding the title string is important – it signifies
that the string is a <em>raw</em> string and not to treat backslashes as
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="http://matplotlib.org/users/mathtext.html#mathtext-tutorial"><span class="std std-ref">Writing mathematical expressions</span></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="http://matplotlib.org/users/usetex.html#usetex-tutorial"><span class="std std-ref">Text rendering With LaTeX</span></a>.</p>
</div>
<div class="section" id="annotating-text">
<h3>Annotating text<a class="headerlink" href="http://matplotlib.org/users/pyplot_tutorial#annotating-text" title="Permalink to this headline">¶</a></h3>
<p>The uses of the basic <a class="reference internal" href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.text" title="matplotlib.pyplot.text"><code class="xref py py-func docutils literal"><span class="pre">text()</span></code></a> command above
place text at an arbitrary position on the Axes. A common use for
text is to annotate some feature of the plot, and the
<a class="reference internal" href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.annotate" title="matplotlib.pyplot.annotate"><code class="xref py py-func docutils literal"><span class="pre">annotate()</span></code></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 <code class="docutils literal"><span class="pre">xy</span></code> and the location of the text <code class="docutils literal"><span class="pre">xytext</span></code>. Both of
these arguments are <code class="docutils literal"><span class="pre">(x,y)</span></code> tuples.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><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="s1">'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="s1">'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="http://matplotlib.org/mpl_examples/pyplots/pyplot_annotate.py">Source code</a>, <a class="reference external" href="http://matplotlib.org/mpl_examples/pyplots/pyplot_annotate.png">png</a>, <a class="reference external" href="http://matplotlib.org/mpl_examples/pyplots/pyplot_annotate.pdf">pdf</a>)</p>
<div class="figure">
<img alt="../_images/pyplot_annotate.png" src="./Pyplot tutorial — Matplotlib 2.0.0 documentation_files/pyplot_annotate.png">
</div>
<p>In this basic example, both the <code class="docutils literal"><span class="pre">xy</span></code> (arrow tip) and <code class="docutils literal"><span class="pre">xytext</span></code>
locations (text location) are in data coordinates. There are a
variety of other coordinate systems one can choose – see
<a class="reference internal" href="http://matplotlib.org/users/annotations.html#annotations-tutorial"><span class="std std-ref">Basic annotation</span></a> and <a class="reference internal" href="http://matplotlib.org/users/annotations.html#plotting-guide-annotation"><span class="std std-ref">Advanced Annotation</span></a> for
details. More examples can be found in
<a class="reference internal" href="http://matplotlib.org/examples/pylab_examples/annotation_demo.html#pylab-examples-annotation-demo"><span class="std std-ref">pylab_examples example code: annotation_demo.py</span></a>.</p>
</div>
</div>
<div class="section" id="logarithmic-and-other-nonlinear-axis">
<h2>Logarithmic and other nonlinear axis<a class="headerlink" href="http://matplotlib.org/users/pyplot_tutorial#logarithmic-and-other-nonlinear-axis" title="Permalink to this headline">¶</a></h2>
<p><a class="reference internal" href="http://matplotlib.org/api/pyplot_api.html#module-matplotlib.pyplot" title="matplotlib.pyplot"><code class="xref py py-mod docutils literal"><span class="pre">matplotlib.pyplot</span></code></a> supports not only linear axis scales, but also
logarithmic and logit scales. This is commonly used if data spans many orders
of magnitude. Changing the scale of an axis is easy:</p>
<blockquote>
<div>plt.xscale(‘log’)</div></blockquote>
<p>An example of four plots with the same data and different scales for the y axis
is shown below.</p>
<div class="highlight-python"><div class="highlight"><pre><span></span><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="kn">from</span> <span class="nn">matplotlib.ticker</span> <span class="kn">import</span> <span class="n">NullFormatter</span> <span class="c1"># useful for `logit` scale</span>
<span class="c1"># Fixing random state for reproducibility</span>
<span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">seed</span><span class="p">(</span><span class="mi">19680801</span><span class="p">)</span>
<span class="c1"># make up some data in the interval ]0, 1[</span>
<span class="n">y</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">normal</span><span class="p">(</span><span class="n">loc</span><span class="o">=</span><span class="mf">0.5</span><span class="p">,</span> <span class="n">scale</span><span class="o">=</span><span class="mf">0.4</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">1000</span><span class="p">)</span>
<span class="n">y</span> <span class="o">=</span> <span class="n">y</span><span class="p">[(</span><span class="n">y</span> <span class="o">></span> <span class="mi">0</span><span class="p">)</span> <span class="o">&</span> <span class="p">(</span><span class="n">y</span> <span class="o"><</span> <span class="mi">1</span><span class="p">)]</span>
<span class="n">y</span><span class="o">.</span><span class="n">sort</span><span class="p">()</span>
<span class="n">x</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="nb">len</span><span class="p">(</span><span class="n">y</span><span class="p">))</span>
<span class="c1"># plot with various axes scales</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="c1"># linear</span>
<span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">221</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">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">yscale</span><span class="p">(</span><span class="s1">'linear'</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="s1">'linear'</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="c1"># log</span>
<span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">222</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">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">yscale</span><span class="p">(</span><span class="s1">'log'</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="s1">'log'</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="c1"># symmetric log</span>
<span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">223</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">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">-</span> <span class="n">y</span><span class="o">.</span><span class="n">mean</span><span class="p">())</span>
<span class="n">plt</span><span class="o">.</span><span class="n">yscale</span><span class="p">(</span><span class="s1">'symlog'</span><span class="p">,</span> <span class="n">linthreshy</span><span class="o">=</span><span class="mf">0.01</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="s1">'symlog'</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="c1"># logit</span>
<span class="n">plt</span><span class="o">.</span><span class="n">subplot</span><span class="p">(</span><span class="mi">224</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">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">yscale</span><span class="p">(</span><span class="s1">'logit'</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="s1">'logit'</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="c1"># Format the minor tick labels of the y-axis into empty strings with</span>
<span class="c1"># `NullFormatter`, to avoid cumbering the axis with too many labels.</span>
<span class="n">plt</span><span class="o">.</span><span class="n">gca</span><span class="p">()</span><span class="o">.</span><span class="n">yaxis</span><span class="o">.</span><span class="n">set_minor_formatter</span><span class="p">(</span><span class="n">NullFormatter</span><span class="p">())</span>
<span class="c1"># Adjust the subplot layout, because the logit one may take more space</span>
<span class="c1"># than usual, due to y-tick labels like "1 - 10^{-3}"</span>
<span class="n">plt</span><span class="o">.</span><span class="n">subplots_adjust</span><span class="p">(</span><span class="n">top</span><span class="o">=</span><span class="mf">0.92</span><span class="p">,</span> <span class="n">bottom</span><span class="o">=</span><span class="mf">0.08</span><span class="p">,</span> <span class="n">left</span><span class="o">=</span><span class="mf">0.10</span><span class="p">,</span> <span class="n">right</span><span class="o">=</span><span class="mf">0.95</span><span class="p">,</span> <span class="n">hspace</span><span class="o">=</span><span class="mf">0.25</span><span class="p">,</span>
<span class="n">wspace</span><span class="o">=</span><span class="mf">0.35</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="http://matplotlib.org/mpl_examples/pyplots/pyplot_scales.py">Source code</a>, <a class="reference external" href="http://matplotlib.org/mpl_examples/pyplots/pyplot_scales.png">png</a>, <a class="reference external" href="http://matplotlib.org/mpl_examples/pyplots/pyplot_scales.pdf">pdf</a>)</p>
<div class="figure">
<img alt="../_images/pyplot_scales.png" src="./Pyplot tutorial — Matplotlib 2.0.0 documentation_files/pyplot_scales.png">
</div>
<p>It is also possible to add your own scale, see <a class="reference internal" href="http://matplotlib.org/devel/add_new_projection.html#adding-new-scales"><span class="std std-ref">Developer’s guide for creating scales and transformations</span></a> for
details.</p>
</div>
</div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
© Copyright 2002 - 2012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom and the Matplotlib development team; 2012 - 2016 The Matplotlib development team.
Last updated on Feb 20, 2017.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.5.2.
</div>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-55954603-1', 'auto');
ga('send', 'pageview');
</script>
<footer>
<!--Flipcause Integration v3.0// Flipcause Integration Instructions:
Install the following code block once in the website Header (after <head> tag) -->
<style>
.fc-black_overlay{
display:none; position: fixed; z-index:1000001; top: 0%;left: 0%;width: 100%;height: 100%;
background-color: black; filter: alpha(opacity=50); cursor:pointer; opacity:0.5;
}
.fc-white_content {
opacity:1; display:none; margin-top: -320px; margin-left: -485px; width:970px; height:640px;
position:fixed; top:50%; left:50%; border: none;z-index:1000002;overflow: auto;
}
.fc-main-box{
opacity:1; display:none; margin:15px auto 0 auto; width:930px; position:relative; z-index:1000003;
}
.fc-widget_close{
opacity:1; content:url(http://i1338.photobucket.com/albums/o691/WeCause/X_zpse4a7e538.png);
position:absolute; z-index=1000004; right:-16px; top:-16px; display:block; cursor:pointer;
}
.floating_button{
display: block; margin-top: 0px; margin-left: 0px; width:auto ; height: auto;
position:fixed; z-index:999999; overflow: auto;
}
@keyframes backfadesin {
from { opacity:0; }
to {opacity:.5;}
}
@-moz-keyframes backfadesin {
from { opacity:0; }
to {opacity:.5;}
}
@-webkit-keyframes backfadesin {
from { opacity:0; }
to {opacity:.5;}
}
@-o-keyframes backfadesin {
from { opacity:0; }
to {opacity:.5;}
}
@-ms-keyframes backfadesin {
from { opacity:0; }
to {opacity:.5;}
}
@keyframes fadesin {
0%{ opacity:0; }
50%{ opacity:0; }
75% {opacity: 0; transform: translateY(20px);}
100% {opacity: 1; transform: translateY(0);}
}
@-moz-keyframes fadesin {
0%{ opacity:0; }
50%{ opacity:0; }
75% {opacity: 0; -moz-transform: translateY(20px);}
100% {opacity: 1; -moz-transform: translateY(0);}
}
@-webkit-keyframes fadesin {
0%{ opacity:0; }
50%{ opacity:0; }
75% {opacity: 0; -webkit-transform: translateY(20px);}
100% {opacity: 1; -webkit-transform: translateY(0);}
}
@-o-keyframes fadesin {
0%{ opacity:0; }
50%{ opacity:0; }
75% {opacity: 0; -o-transform: translateY(20px);}
100% {opacity: 1; -o-transform: translateY(0);}
}
@-ms-keyframes fadesin {
0%{ opacity:0; }
50%{ opacity:0; }
75% {opacity: 0; -ms-transform: translateY(20px);}
100% {opacity: 1; -ms-transform: translateY(0);}
}
</style>
<script>
function open_window(cause_id) {
var protocol=String(document.location.protocol);
var new_url;
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)){
new_url="https://www.flipcause.com/widget/"+cause_id
window.open(new_url);
}
else {
document.getElementById("fc-fade").style.display = "block";
document.getElementById("fc-fade").style.webkitAnimation = "backfadesin 1s";
document.getElementById("fc-fade").style.animation = "backfadesin 1s";
document.getElementById("fc-fade").style.mozAnimation = "backfadesin 1s";
document.getElementById("fc-light").style.display = "block";
document.getElementById("fc-light").style.webkitAnimation = "fadesin 1.5s";
document.getElementById("fc-light").style.animation = "fadesin 1.5s";
document.getElementById("fc-light").style.mozAnimation = "fadesin 1.5s";
document.getElementById("fc-main").style.display = "block";
document.getElementById("fc-main").style.webkitAnimation = "fadesin 1.5s";
document.getElementById("fc-main").style.animation = "fadesin 1.5s";
document.getElementById("fc-main").style.mozAnimation = "fadesin 1.5s";
document.getElementById("fc-close").style.display = "block";
document.getElementById("fc-close").style.webkitAnimation = "fadesin 1.5s";
document.getElementById("fc-close").style.animation = "fadesin 1.5s";
document.getElementById("fc-close").style.mozAnimation = "fadesin 1.5s";
document.getElementById("fc-myFrame").style.display = "block";
document.getElementById("fc-myFrame").style.webkitAnimation = "fadesin 1.5s";
document.getElementById("fc-myFrame").style.animation = "fadesin 1.5s";
document.getElementById("fc-myFrame").style.mozAnimation = "fadesin 1.5s";
document.getElementById("fc-myFrame").src="https://www.flipcause.com/widget/"+cause_id;
}
}
function close_window() {
document.getElementById("fc-fade").style.display="none";
document.getElementById("fc-light").style.display="none";
document.getElementById("fc-main").style.display="none";
document.getElementById("fc-close").style.display="none";
document.getElementById("fc-myFrame").style.display="none";
}
</script>
<div id="fc-fade" class="fc-black_overlay" onclick="close_window()"></div>
<div id="fc-light" class="fc-white_content">
<div id="fc-main" class="fc-main-box">
<div id="fc-close" class="fc-widget_close" onclick="close_window()">
</div><iframe id="fc-myFrame" iframe="" height="580" width="925" style="border: 0;
border-radius:5px 5px 5px 5px; box-shadow:0 0 8px rgba(0, 0, 0, 0.5);" scrolling="no" src="./Pyplot tutorial — Matplotlib 2.0.0 documentation_files/saved_resource.html"></iframe></div>
</div>
<!--END Flipcause Main Integration Code-->
</footer>
</body></html>