-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathannotations.html
More file actions
1203 lines (1013 loc) · 92 KB
/
annotations.html
File metadata and controls
1203 lines (1013 loc) · 92 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
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
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<meta content="codex" name="keywords" />
<title>Annotations — Matplotlib 3.6.3 documentation</title>
<script data-cfasync="false">
document.documentElement.dataset.mode = localStorage.getItem("mode") || "";
document.documentElement.dataset.theme = localStorage.getItem("theme") || "light";
</script>
<!-- Loaded before other Sphinx assets -->
<link href="../../_static/styles/theme.css?digest=796348d33e8b1d947c94" rel="stylesheet">
<link href="../../_static/styles/bootstrap.css?digest=796348d33e8b1d947c94" rel="stylesheet">
<link href="../../_static/styles/pydata-sphinx-theme.css?digest=796348d33e8b1d947c94" rel="stylesheet">
<link href="../../_static/vendor/fontawesome/6.1.2/css/all.min.css?digest=796348d33e8b1d947c94" rel="stylesheet">
<link rel="preload" as="font" type="font/woff2" crossorigin href="../../_static/vendor/fontawesome/6.1.2/webfonts/fa-solid-900.woff2">
<link rel="preload" as="font" type="font/woff2" crossorigin href="../../_static/vendor/fontawesome/6.1.2/webfonts/fa-brands-400.woff2">
<link rel="preload" as="font" type="font/woff2" crossorigin href="../../_static/vendor/fontawesome/6.1.2/webfonts/fa-regular-400.woff2">
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v3.6.3-3-g655f616e86" />
<link rel="stylesheet" type="text/css" href="../../_static/css/style.css?v3.6.3-3-g655f616e86" />
<link rel="stylesheet" type="text/css" href="../../_static/graphviz.css?v3.6.3-3-g655f616e86" />
<link rel="stylesheet" type="text/css" href="../../_static/plot_directive.css?v3.6.3-3-g655f616e86" />
<link rel="stylesheet" type="text/css" href="../../_static/copybutton.css?v3.6.3-3-g655f616e86" />
<link rel="stylesheet" type="text/css" href="../../_static/sg_gallery.css?v3.6.3-3-g655f616e86" />
<link rel="stylesheet" type="text/css" href="../../_static/sg_gallery-binder.css?v3.6.3-3-g655f616e86" />
<link rel="stylesheet" type="text/css" href="../../_static/sg_gallery-dataframe.css?v3.6.3-3-g655f616e86" />
<link rel="stylesheet" type="text/css" href="../../_static/sg_gallery-rendered-html.css?v3.6.3-3-g655f616e86" />
<link rel="stylesheet" type="text/css" href="../../_static/design-style.4045f2051d55cab465a707391d5b2007.min.css?v3.6.3-3-g655f616e86" />
<link rel="stylesheet" type="text/css" href="../../_static/mpl.css?v3.6.3-3-g655f616e86" />
<!-- Pre-loaded scripts that we'll load fully later -->
<link rel="preload" as="script" href="../../_static/scripts/bootstrap.js?digest=796348d33e8b1d947c94">
<link rel="preload" as="script" href="../../_static/scripts/pydata-sphinx-theme.js?digest=796348d33e8b1d947c94">
<script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js?v3.6.3-3-g655f616e86"></script>
<script src="../../_static/jquery.js?v3.6.3-3-g655f616e86"></script>
<script src="../../_static/underscore.js?v3.6.3-3-g655f616e86"></script>
<script src="../../_static/_sphinx_javascript_frameworks_compat.js?v3.6.3-3-g655f616e86"></script>
<script src="../../_static/doctools.js?v3.6.3-3-g655f616e86"></script>
<script src="../../_static/sphinx_highlight.js?v3.6.3-3-g655f616e86"></script>
<script src="../../_static/clipboard.min.js?v3.6.3-3-g655f616e86"></script>
<script src="../../_static/copybutton.js?v3.6.3-3-g655f616e86"></script>
<script src="../../_static/design-tabs.js?v3.6.3-3-g655f616e86"></script>
<script data-domain="matplotlib.org" defer="defer" src="https://views.scientific-python.org/js/script.js"></script>
<script>DOCUMENTATION_OPTIONS.pagename = 'tutorials/text/annotations';</script>
<script>
DOCUMENTATION_OPTIONS.theme_switcher_json_url = 'https://matplotlib.org/devdocs/_static/switcher.json';
DOCUMENTATION_OPTIONS.theme_switcher_version_match = '3.6.3';
</script>
<link rel="canonical" href="https://matplotlib.org/stable/tutorials/text/annotations.html" />
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Matplotlib 3.6.3 documentation"
href="../../_static/opensearch.xml"/>
<link rel="shortcut icon" href="../../_static/favicon.ico"/>
<link rel="search" title="Search" href="../../search.html" />
<link rel="next" title="Writing mathematical expressions" href="mathtext.html" />
<link rel="prev" title="Text properties and layout" href="text_props.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="en">
</head>
<body data-spy="scroll" data-target="#bd-toc-nav" data-offset="180" data-default-mode="">
<a class="skip-link" href="#main-content">Skip to main content</a>
<input type="checkbox" class="sidebar-toggle" name="__primary" id="__primary">
<label class="overlay overlay-primary" for="__primary"></label>
<input type="checkbox" class="sidebar-toggle" name="__secondary" id="__secondary">
<label class="overlay overlay-secondary" for="__secondary"></label>
<div class="search-button__wrapper">
<div class="search-button__overlay"></div>
<div class="search-button__search-container">
<form class="bd-search d-flex align-items-center" action="../../search.html" method="get">
<i class="fa-solid fa-magnifying-glass"></i>
<input type="search" class="form-control" name="q" id="search-input" placeholder="Search the docs ..." aria-label="Search the docs ..." autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
<span class="search-button__kbd-shortcut"><kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd>K</kbd></span>
</form>
</div>
</div>
<nav class="bd-header navbar navbar-expand-lg bd-navbar" id="navbar-main"><div class="bd-header__inner bd-page-width">
<label class="sidebar-toggle primary-toggle" for="__primary">
<span class="fa-solid fa-bars"></span>
</label>
<div id="navbar-start">
<a class="navbar-brand logo" href="../../index.html">
<img src="../../_static/images/logo2.svg" class="logo__image only-light" alt="Logo image">
<img src="../../_static/images/logo_dark.svg" class="logo__image only-dark" alt="Logo image">
</a>
</div>
<div class="col-lg-9 navbar-header-items">
<div id="navbar-center" class="mr-auto">
<div class="navbar-center-item">
<ul id="navbar-main-elements" class="navbar-nav">
<li class="nav-item">
<a class="reference internal nav-link" href="../../plot_types/index.html">Plot types</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="../../gallery/index.html">Examples</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="../index.html">Tutorials</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="../../api/index.html">Reference</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="../../users/index.html">User guide</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="../../devel/index.html">Develop</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="../../users/release_notes.html">Release notes</a>
</li>
</ul>
</div>
</div>
<div id="navbar-end">
<div class="navbar-end-item navbar-persistent--container">
<button class="btn btn-sm navbar-btn search-button search-button__button" title="Search" aria-label="Search" data-toggle="tooltip">
<i class="fa-solid fa-magnifying-glass"></i>
</button>
</div>
<div class="navbar-end-item">
<button class="theme-switch-button btn btn-sm btn-outline-primary navbar-btn rounded-circle" title="light/dark" aria-label="light/dark" data-toggle="tooltip">
<span class="theme-switch" data-mode="light"><i class="fa-solid fa-sun"></i></span>
<span class="theme-switch" data-mode="dark"><i class="fa-solid fa-moon"></i></span>
<span class="theme-switch" data-mode="auto"><i class="fa-solid fa-circle-half-stroke"></i></span>
</button>
</div>
<div class="navbar-end-item">
<div class="version-switcher__container dropdown">
<button type="button" class="version-switcher__button btn btn-sm navbar-btn dropdown-toggle" data-toggle="dropdown">
stable <!-- this text may get changed later by javascript -->
<span class="caret"></span>
</button>
<div class="version-switcher__menu dropdown-menu list-group-flush py-0">
<!-- dropdown will be populated by javascript on page load -->
</div>
</div>
</div>
<div class="navbar-end-item">
<ul id="navbar-icon-links" class="navbar-nav" aria-label="Icon Links">
<li class="nav-item">
<a href="https://gitter.im/matplotlib/matplotlib" title="Gitter" class="nav-link" rel="noopener" target="_blank" data-toggle="tooltip"><span><i class="fab fa-gitter"></i></span>
<label class="sr-only">Gitter</label></a>
</li>
<li class="nav-item">
<a href="https://discourse.matplotlib.org" title="Discourse" class="nav-link" rel="noopener" target="_blank" data-toggle="tooltip"><span><i class="fab fa-discourse"></i></span>
<label class="sr-only">Discourse</label></a>
</li>
<li class="nav-item">
<a href="https://github.com/matplotlib/matplotlib" title="GitHub" class="nav-link" rel="noopener" target="_blank" data-toggle="tooltip"><span><i class="fab fa-github"></i></span>
<label class="sr-only">GitHub</label></a>
</li>
<li class="nav-item">
<a href="https://twitter.com/matplotlib/" title="Twitter" class="nav-link" rel="noopener" target="_blank" data-toggle="tooltip"><span><i class="fab fa-twitter"></i></span>
<label class="sr-only">Twitter</label></a>
</li>
</ul>
</div>
</div>
</div>
<div class="navbar-persistent--mobile">
<button class="btn btn-sm navbar-btn search-button search-button__button" title="Search" aria-label="Search" data-toggle="tooltip">
<i class="fa-solid fa-magnifying-glass"></i>
</button>
</div>
<label class="sidebar-toggle secondary-toggle" for="__secondary">
<span class="fa-solid fa-outdent"></span>
</label>
</div>
</nav>
<div class="bd-container">
<div class="bd-container__inner bd-page-width">
<div class="bd-sidebar-primary bd-sidebar">
<div class="sidebar-header-items sidebar-primary__section">
<div class="sidebar-header-items__center">
<div class="navbar-center-item">
<ul id="navbar-main-elements" class="navbar-nav">
<li class="nav-item">
<a class="reference internal nav-link" href="../../plot_types/index.html">Plot types</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="../../gallery/index.html">Examples</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="../index.html">Tutorials</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="../../api/index.html">Reference</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="../../users/index.html">User guide</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="../../devel/index.html">Develop</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="../../users/release_notes.html">Release notes</a>
</li>
</ul>
</div>
</div>
<div class="sidebar-header-items__end">
<div class="navbar-end-item">
<button class="theme-switch-button btn btn-sm btn-outline-primary navbar-btn rounded-circle" title="light/dark" aria-label="light/dark" data-toggle="tooltip">
<span class="theme-switch" data-mode="light"><i class="fa-solid fa-sun"></i></span>
<span class="theme-switch" data-mode="dark"><i class="fa-solid fa-moon"></i></span>
<span class="theme-switch" data-mode="auto"><i class="fa-solid fa-circle-half-stroke"></i></span>
</button>
</div>
<div class="navbar-end-item">
<div class="version-switcher__container dropdown">
<button type="button" class="version-switcher__button btn btn-sm navbar-btn dropdown-toggle" data-toggle="dropdown">
stable <!-- this text may get changed later by javascript -->
<span class="caret"></span>
</button>
<div class="version-switcher__menu dropdown-menu list-group-flush py-0">
<!-- dropdown will be populated by javascript on page load -->
</div>
</div>
</div>
<div class="navbar-end-item">
<ul id="navbar-icon-links" class="navbar-nav" aria-label="Icon Links">
<li class="nav-item">
<a href="https://gitter.im/matplotlib/matplotlib" title="Gitter" class="nav-link" rel="noopener" target="_blank" data-toggle="tooltip"><span><i class="fab fa-gitter"></i></span>
<label class="sr-only">Gitter</label></a>
</li>
<li class="nav-item">
<a href="https://discourse.matplotlib.org" title="Discourse" class="nav-link" rel="noopener" target="_blank" data-toggle="tooltip"><span><i class="fab fa-discourse"></i></span>
<label class="sr-only">Discourse</label></a>
</li>
<li class="nav-item">
<a href="https://github.com/matplotlib/matplotlib" title="GitHub" class="nav-link" rel="noopener" target="_blank" data-toggle="tooltip"><span><i class="fab fa-github"></i></span>
<label class="sr-only">GitHub</label></a>
</li>
<li class="nav-item">
<a href="https://twitter.com/matplotlib/" title="Twitter" class="nav-link" rel="noopener" target="_blank" data-toggle="tooltip"><span><i class="fab fa-twitter"></i></span>
<label class="sr-only">Twitter</label></a>
</li>
</ul>
</div>
</div>
</div>
<div class="sidebar-start-items sidebar-primary__section">
<div class="sidebar-start-items__item"><nav class="bd-links" id="bd-docs-nav" aria-label="Section navigation">
<p class="bd-links__title" role="heading" aria-level="1">
Section Navigation
</p>
<div class="bd-toc-item navbar-nav">
<ul class="current nav bd-sidenav">
<li class="toctree-l1 has-children"><a class="reference internal" href="../introductory/index.html">Introductory</a><input class="toctree-checkbox" id="toctree-checkbox-1" name="toctree-checkbox-1" type="checkbox"/><label class="toctree-toggle" for="toctree-checkbox-1"><i class="fa-solid fa-chevron-down"></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="../introductory/quick_start.html">Quick start guide</a></li>
<li class="toctree-l2"><a class="reference internal" href="../introductory/pyplot.html">Pyplot tutorial</a></li>
<li class="toctree-l2"><a class="reference internal" href="../introductory/images.html">Image tutorial</a></li>
<li class="toctree-l2"><a class="reference internal" href="../introductory/lifecycle.html">The Lifecycle of a Plot</a></li>
<li class="toctree-l2"><a class="reference internal" href="../introductory/customizing.html">Customizing Matplotlib with style sheets and rcParams</a></li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../intermediate/index.html">Intermediate</a><input class="toctree-checkbox" id="toctree-checkbox-2" name="toctree-checkbox-2" type="checkbox"/><label class="toctree-toggle" for="toctree-checkbox-2"><i class="fa-solid fa-chevron-down"></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="../intermediate/artists.html">Artist tutorial</a></li>
<li class="toctree-l2"><a class="reference internal" href="../intermediate/legend_guide.html">Legend guide</a></li>
<li class="toctree-l2"><a class="reference internal" href="../intermediate/color_cycle.html">Styling with cycler</a></li>
<li class="toctree-l2"><a class="reference internal" href="../intermediate/constrainedlayout_guide.html">Constrained Layout Guide</a></li>
<li class="toctree-l2"><a class="reference internal" href="../intermediate/tight_layout_guide.html">Tight Layout guide</a></li>
<li class="toctree-l2"><a class="reference internal" href="../intermediate/arranging_axes.html">Arranging multiple Axes in a Figure</a></li>
<li class="toctree-l2"><a class="reference internal" href="../intermediate/autoscale.html">Autoscaling</a></li>
<li class="toctree-l2"><a class="reference internal" href="../intermediate/imshow_extent.html"><em>origin</em> and <em>extent</em> in <code class="xref py py-obj docutils literal notranslate"><span class="pre">imshow</span></code></a></li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../advanced/index.html">Advanced</a><input class="toctree-checkbox" id="toctree-checkbox-3" name="toctree-checkbox-3" type="checkbox"/><label class="toctree-toggle" for="toctree-checkbox-3"><i class="fa-solid fa-chevron-down"></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="../advanced/blitting.html">Faster rendering by using blitting</a></li>
<li class="toctree-l2"><a class="reference internal" href="../advanced/path_tutorial.html">Path Tutorial</a></li>
<li class="toctree-l2"><a class="reference internal" href="../advanced/patheffects_guide.html">Path effects guide</a></li>
<li class="toctree-l2"><a class="reference internal" href="../advanced/transforms_tutorial.html">Transformations Tutorial</a></li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../colors/index.html">Colors</a><input class="toctree-checkbox" id="toctree-checkbox-4" name="toctree-checkbox-4" type="checkbox"/><label class="toctree-toggle" for="toctree-checkbox-4"><i class="fa-solid fa-chevron-down"></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="../colors/colors.html">Specifying colors</a></li>
<li class="toctree-l2"><a class="reference internal" href="../colors/colorbar_only.html">Customized Colorbars Tutorial</a></li>
<li class="toctree-l2"><a class="reference internal" href="../colors/colormap-manipulation.html">Creating Colormaps in Matplotlib</a></li>
<li class="toctree-l2"><a class="reference internal" href="../colors/colormapnorms.html">Colormap Normalization</a></li>
<li class="toctree-l2"><a class="reference internal" href="../colors/colormaps.html">Choosing Colormaps in Matplotlib</a></li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../provisional/index.html">Provisional</a><input class="toctree-checkbox" id="toctree-checkbox-5" name="toctree-checkbox-5" type="checkbox"/><label class="toctree-toggle" for="toctree-checkbox-5"><i class="fa-solid fa-chevron-down"></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="../provisional/mosaic.html">Complex and semantic figure composition</a></li>
</ul>
</li>
<li class="toctree-l1 current active has-children"><a class="reference internal" href="index.html">Text</a><input checked="" class="toctree-checkbox" id="toctree-checkbox-6" name="toctree-checkbox-6" type="checkbox"/><label class="toctree-toggle" for="toctree-checkbox-6"><i class="fa-solid fa-chevron-down"></i></label><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="text_intro.html">Text in Matplotlib Plots</a></li>
<li class="toctree-l2"><a class="reference internal" href="text_props.html">Text properties and layout</a></li>
<li class="toctree-l2 current active"><a class="current reference internal" href="#">Annotations</a></li>
<li class="toctree-l2"><a class="reference internal" href="mathtext.html">Writing mathematical expressions</a></li>
<li class="toctree-l2"><a class="reference internal" href="pgf.html">Text rendering with XeLaTeX/LuaLaTeX via the <code class="docutils literal notranslate"><span class="pre">pgf</span></code> backend</a></li>
<li class="toctree-l2"><a class="reference internal" href="usetex.html">Text rendering with LaTeX</a></li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../toolkits/index.html">Toolkits</a><input class="toctree-checkbox" id="toctree-checkbox-7" name="toctree-checkbox-7" type="checkbox"/><label class="toctree-toggle" for="toctree-checkbox-7"><i class="fa-solid fa-chevron-down"></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="../toolkits/axes_grid.html">The axes_grid1 toolkit</a></li>
<li class="toctree-l2"><a class="reference internal" href="../toolkits/axisartist.html">The axisartist toolkit</a></li>
<li class="toctree-l2"><a class="reference internal" href="../toolkits/mplot3d.html">The mplot3d toolkit</a></li>
</ul>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div class="sidebar-end-items sidebar-primary__section">
<div class="sidebar-end-items__item">
</div>
</div>
<div id="rtd-footer-container"></div>
</div>
<main id="main-content" class="bd-main">
<div class="bd-content">
<div class="bd-article-container">
<div class="bd-header-article">
</div>
<article class="bd-article" role="main">
<div class="sphx-glr-download-link-note admonition note">
<p class="admonition-title">Note</p>
<p>Click <a class="reference internal" href="#sphx-glr-download-tutorials-text-annotations-py"><span class="std std-ref">here</span></a>
to download the full example code</p>
</div>
<section class="sphx-glr-example-title" id="annotations">
<span id="sphx-glr-tutorials-text-annotations-py"></span><h1><a class="toc-backref" href="#id1" role="doc-backlink">Annotations</a><a class="headerlink" href="#annotations" title="Permalink to this heading">#</a></h1>
<p>Annotating text with Matplotlib.</p>
<nav class="contents" id="table-of-contents">
<p class="topic-title">Table of Contents</p>
<ul class="simple">
<li><p><a class="reference internal" href="#annotations" id="id1">Annotations</a></p>
<ul>
<li><p><a class="reference internal" href="#basic-annotation" id="id2">Basic annotation</a></p></li>
<li><p><a class="reference internal" href="#advanced-annotations" id="id3">Advanced Annotations</a></p>
<ul>
<li><p><a class="reference internal" href="#annotating-with-text-with-box" id="id4">Annotating with Text with Box</a></p></li>
<li><p><a class="reference internal" href="#annotating-with-arrow" id="id5">Annotating with Arrow</a></p></li>
<li><p><a class="reference internal" href="#placing-artist-at-anchored-axes-locations" id="id6">Placing Artist at anchored Axes locations</a></p></li>
<li><p><a class="reference internal" href="#coordinate-systems-for-annotations" id="id7">Coordinate systems for Annotations</a></p></li>
<li><p><a class="reference internal" href="#using-connectionpatch" id="id8">Using ConnectionPatch</a></p></li>
</ul>
</li>
<li><p><a class="reference internal" href="#advanced-topics" id="id9">Advanced Topics</a></p>
<ul>
<li><p><a class="reference internal" href="#zoom-effect-between-axes" id="id10">Zoom effect between Axes</a></p></li>
<li><p><a class="reference internal" href="#define-custom-boxstyle" id="id11">Define Custom BoxStyle</a></p></li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">matplotlib</span> <span class="kn">import</span> <span class="n">pyplot</span> <span class="k">as</span> <span class="n">plt</span>
</pre></div>
</div>
<section id="basic-annotation">
<span id="annotations-tutorial"></span><h2><a class="toc-backref" href="#id2" role="doc-backlink">Basic annotation</a><a class="headerlink" href="#basic-annotation" title="Permalink to this heading">#</a></h2>
<p>The uses of the basic <a class="reference internal" href="../../api/_as_gen/matplotlib.pyplot.text.html#matplotlib.pyplot.text" title="matplotlib.pyplot.text"><code class="xref py py-func docutils literal notranslate"><span class="pre">text()</span></code></a> will 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/_as_gen/matplotlib.axes.Axes.annotate.html#matplotlib.axes.Axes.annotate" title="matplotlib.axes.Axes.annotate"><code class="xref py py-func docutils literal notranslate"><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
<em>xy</em> and the location of the text <em>xytext</em>. Both of these
arguments are <code class="docutils literal notranslate"><span class="pre">(x,</span> <span class="pre">y)</span></code> tuples.</p>
<figure class="align-center">
<a class="reference external image-reference" href="../../gallery/text_labels_and_annotations/annotation_basic.html"><img alt="../../_images/sphx_glr_annotation_basic_001.png" src="../../_images/sphx_glr_annotation_basic_001.png" /></a>
</figure>
<p>In this example, both the <em>xy</em> (arrow tip) and <em>xytext</em> locations
(text location) are in data coordinates. There are a variety of other
coordinate systems one can choose -- you can specify the coordinate
system of <em>xy</em> and <em>xytext</em> with one of the following strings for
<em>xycoords</em> and <em>textcoords</em> (default is 'data')</p>
<table class="table">
<thead>
<tr class="row-odd"><th class="head"><p>argument</p></th>
<th class="head"><p>coordinate system</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>'figure points'</p></td>
<td><p>points from the lower left corner of the figure</p></td>
</tr>
<tr class="row-odd"><td><p>'figure pixels'</p></td>
<td><p>pixels from the lower left corner of the figure</p></td>
</tr>
<tr class="row-even"><td><p>'figure fraction'</p></td>
<td><p>(0, 0) is lower left of figure and (1, 1) is upper right</p></td>
</tr>
<tr class="row-odd"><td><p>'axes points'</p></td>
<td><p>points from lower left corner of axes</p></td>
</tr>
<tr class="row-even"><td><p>'axes pixels'</p></td>
<td><p>pixels from lower left corner of axes</p></td>
</tr>
<tr class="row-odd"><td><p>'axes fraction'</p></td>
<td><p>(0, 0) is lower left of axes and (1, 1) is upper right</p></td>
</tr>
<tr class="row-even"><td><p>'data'</p></td>
<td><p>use the axes data coordinate system</p></td>
</tr>
</tbody>
</table>
<p>For example to place the text coordinates in fractional axes
coordinates, one could do:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ax</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">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">xycoords</span><span class="o">=</span><span class="s1">'data'</span><span class="p">,</span>
<span class="n">xytext</span><span class="o">=</span><span class="p">(</span><span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.95</span><span class="p">),</span> <span class="n">textcoords</span><span class="o">=</span><span class="s1">'axes fraction'</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="n">horizontalalignment</span><span class="o">=</span><span class="s1">'right'</span><span class="p">,</span> <span class="n">verticalalignment</span><span class="o">=</span><span class="s1">'top'</span><span class="p">,</span>
<span class="p">)</span>
</pre></div>
</div>
<p>For physical coordinate systems (points or pixels) the origin is the
bottom-left of the figure or axes.</p>
<p>Optionally, you can enable drawing of an arrow from the text to the annotated
point by giving a dictionary of arrow properties in the optional keyword
argument <em>arrowprops</em>.</p>
<table class="table">
<thead>
<tr class="row-odd"><th class="head"><p><em>arrowprops</em> key</p></th>
<th class="head"><p>description</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>width</p></td>
<td><p>the width of the arrow in points</p></td>
</tr>
<tr class="row-odd"><td><p>frac</p></td>
<td><p>the fraction of the arrow length occupied by the head</p></td>
</tr>
<tr class="row-even"><td><p>headwidth</p></td>
<td><p>the width of the base of the arrow head in points</p></td>
</tr>
<tr class="row-odd"><td><p>shrink</p></td>
<td><p>move the tip and base some percent away from
the annotated point and text</p></td>
</tr>
<tr class="row-even"><td><p>**kwargs</p></td>
<td><p>any key for <a class="reference internal" href="../../api/_as_gen/matplotlib.patches.Polygon.html#matplotlib.patches.Polygon" title="matplotlib.patches.Polygon"><code class="xref py py-class docutils literal notranslate"><span class="pre">matplotlib.patches.Polygon</span></code></a>,
e.g., <code class="docutils literal notranslate"><span class="pre">facecolor</span></code></p></td>
</tr>
</tbody>
</table>
<p>In the example below, the <em>xy</em> point is in native coordinates
(<em>xycoords</em> defaults to 'data'). For a polar axes, this is in
(theta, radius) space. The text in this example is placed in the
fractional figure coordinate system. <a class="reference internal" href="../../api/text_api.html#matplotlib.text.Text" title="matplotlib.text.Text"><code class="xref py py-class docutils literal notranslate"><span class="pre">matplotlib.text.Text</span></code></a>
keyword arguments like <em>horizontalalignment</em>, <em>verticalalignment</em> and
<em>fontsize</em> are passed from <a class="reference internal" href="../../api/_as_gen/matplotlib.axes.Axes.annotate.html#matplotlib.axes.Axes.annotate" title="matplotlib.axes.Axes.annotate"><code class="xref py py-obj docutils literal notranslate"><span class="pre">annotate</span></code></a> to the
<code class="docutils literal notranslate"><span class="pre">Text</span></code> instance.</p>
<figure class="align-center">
<a class="reference external image-reference" href="../../gallery/text_labels_and_annotations/annotation_polar.html"><img alt="../../_images/sphx_glr_annotation_polar_001.png" src="../../_images/sphx_glr_annotation_polar_001.png" /></a>
</figure>
<p>For more on all the wild and wonderful things you can do with
annotations, including fancy arrows, see <a class="reference internal" href="#plotting-guide-annotation"><span class="std std-ref">Advanced Annotations</span></a>
and <a class="reference internal" href="../../gallery/text_labels_and_annotations/annotation_demo.html"><span class="doc">Annotating Plots</span></a>.</p>
<p>Do not proceed unless you have already read <a class="reference internal" href="#annotations-tutorial"><span class="std std-ref">Basic annotation</span></a>,
<a class="reference internal" href="../../api/_as_gen/matplotlib.pyplot.text.html#matplotlib.pyplot.text" title="matplotlib.pyplot.text"><code class="xref py py-func docutils literal notranslate"><span class="pre">text()</span></code></a> and <a class="reference internal" href="../../api/_as_gen/matplotlib.pyplot.annotate.html#matplotlib.pyplot.annotate" title="matplotlib.pyplot.annotate"><code class="xref py py-func docutils literal notranslate"><span class="pre">annotate()</span></code></a>!</p>
</section>
<section id="advanced-annotations">
<span id="plotting-guide-annotation"></span><h2><a class="toc-backref" href="#id3" role="doc-backlink">Advanced Annotations</a><a class="headerlink" href="#advanced-annotations" title="Permalink to this heading">#</a></h2>
<section id="annotating-with-text-with-box">
<h3><a class="toc-backref" href="#id4" role="doc-backlink">Annotating with Text with Box</a><a class="headerlink" href="#annotating-with-text-with-box" title="Permalink to this heading">#</a></h3>
<p>Let's start with a simple example.</p>
<figure class="align-center">
<a class="reference external image-reference" href="../../gallery/userdemo/annotate_text_arrow.html"><img alt="../../_images/sphx_glr_annotate_text_arrow_001.png" src="../../_images/sphx_glr_annotate_text_arrow_001.png" /></a>
</figure>
<p><a class="reference internal" href="../../api/_as_gen/matplotlib.axes.Axes.text.html#matplotlib.axes.Axes.text" title="matplotlib.axes.Axes.text"><code class="xref py py-obj docutils literal notranslate"><span class="pre">text</span></code></a> takes a <em>bbox</em> keyword argument, which draws a box around the
text:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">t</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">text</span><span class="p">(</span>
<span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="s2">"Direction"</span><span class="p">,</span> <span class="n">ha</span><span class="o">=</span><span class="s2">"center"</span><span class="p">,</span> <span class="n">va</span><span class="o">=</span><span class="s2">"center"</span><span class="p">,</span> <span class="n">rotation</span><span class="o">=</span><span class="mi">45</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="mi">15</span><span class="p">,</span>
<span class="n">bbox</span><span class="o">=</span><span class="nb">dict</span><span class="p">(</span><span class="n">boxstyle</span><span class="o">=</span><span class="s2">"rarrow,pad=0.3"</span><span class="p">,</span> <span class="n">fc</span><span class="o">=</span><span class="s2">"cyan"</span><span class="p">,</span> <span class="n">ec</span><span class="o">=</span><span class="s2">"b"</span><span class="p">,</span> <span class="n">lw</span><span class="o">=</span><span class="mi">2</span><span class="p">))</span>
</pre></div>
</div>
<p>The patch object associated with the text can be accessed by:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">bb</span> <span class="o">=</span> <span class="n">t</span><span class="o">.</span><span class="n">get_bbox_patch</span><span class="p">()</span>
</pre></div>
</div>
<p>The return value is a <a class="reference internal" href="../../api/_as_gen/matplotlib.patches.FancyBboxPatch.html#matplotlib.patches.FancyBboxPatch" title="matplotlib.patches.FancyBboxPatch"><code class="xref py py-obj docutils literal notranslate"><span class="pre">FancyBboxPatch</span></code></a>; patch properties
(facecolor, edgewidth, etc.) can be accessed and modified as usual.
<a class="reference internal" href="../../api/_as_gen/matplotlib.patches.FancyBboxPatch.html#matplotlib.patches.FancyBboxPatch.set_boxstyle" title="matplotlib.patches.FancyBboxPatch.set_boxstyle"><code class="xref py py-obj docutils literal notranslate"><span class="pre">FancyBboxPatch.set_boxstyle</span></code></a> sets the box shape:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">bb</span><span class="o">.</span><span class="n">set_boxstyle</span><span class="p">(</span><span class="s2">"rarrow"</span><span class="p">,</span> <span class="n">pad</span><span class="o">=</span><span class="mf">0.6</span><span class="p">)</span>
</pre></div>
</div>
<p>The arguments are the name of the box style with its attributes as
keyword arguments. Currently, following box styles are implemented.</p>
<blockquote>
<div><table class="table">
<thead>
<tr class="row-odd"><th class="head"><p>Class</p></th>
<th class="head"><p>Name</p></th>
<th class="head"><p>Attrs</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>Circle</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">circle</span></code></p></td>
<td><p>pad=0.3</p></td>
</tr>
<tr class="row-odd"><td><p>DArrow</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">darrow</span></code></p></td>
<td><p>pad=0.3</p></td>
</tr>
<tr class="row-even"><td><p>LArrow</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">larrow</span></code></p></td>
<td><p>pad=0.3</p></td>
</tr>
<tr class="row-odd"><td><p>RArrow</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">rarrow</span></code></p></td>
<td><p>pad=0.3</p></td>
</tr>
<tr class="row-even"><td><p>Round</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">round</span></code></p></td>
<td><p>pad=0.3,rounding_size=None</p></td>
</tr>
<tr class="row-odd"><td><p>Round4</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">round4</span></code></p></td>
<td><p>pad=0.3,rounding_size=None</p></td>
</tr>
<tr class="row-even"><td><p>Roundtooth</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">roundtooth</span></code></p></td>
<td><p>pad=0.3,tooth_size=None</p></td>
</tr>
<tr class="row-odd"><td><p>Sawtooth</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">sawtooth</span></code></p></td>
<td><p>pad=0.3,tooth_size=None</p></td>
</tr>
<tr class="row-even"><td><p>Square</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">square</span></code></p></td>
<td><p>pad=0.3</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<figure class="align-center">
<a class="reference external image-reference" href="../../gallery/shapes_and_collections/fancybox_demo.html"><img alt="../../_images/sphx_glr_fancybox_demo_001.png" src="../../_images/sphx_glr_fancybox_demo_001.png" /></a>
</figure>
<p>Note that the attribute arguments can be specified within the style
name with separating comma (this form can be used as "boxstyle" value
of bbox argument when initializing the text instance)</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">bb</span><span class="o">.</span><span class="n">set_boxstyle</span><span class="p">(</span><span class="s2">"rarrow,pad=0.6"</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="annotating-with-arrow">
<h3><a class="toc-backref" href="#id5" role="doc-backlink">Annotating with Arrow</a><a class="headerlink" href="#annotating-with-arrow" title="Permalink to this heading">#</a></h3>
<p><a class="reference internal" href="../../api/_as_gen/matplotlib.axes.Axes.annotate.html#matplotlib.axes.Axes.annotate" title="matplotlib.axes.Axes.annotate"><code class="xref py py-obj docutils literal notranslate"><span class="pre">annotate</span></code></a> draws an arrow connecting two points in an Axes:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ax</span><span class="o">.</span><span class="n">annotate</span><span class="p">(</span><span class="s2">"Annotation"</span><span class="p">,</span>
<span class="n">xy</span><span class="o">=</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">xycoords</span><span class="o">=</span><span class="s1">'data'</span><span class="p">,</span>
<span class="n">xytext</span><span class="o">=</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="n">textcoords</span><span class="o">=</span><span class="s1">'offset points'</span><span class="p">,</span>
<span class="p">)</span>
</pre></div>
</div>
<p>This annotates a point at <em>xy</em> in the given coordinate (<em>xycoords</em>)
with the text at <em>xytext</em> given in <em>textcoords</em>. Often, the
annotated point is specified in the <em>data</em> coordinate and the annotating
text in <em>offset points</em>.
See <a class="reference internal" href="../../api/_as_gen/matplotlib.axes.Axes.annotate.html#matplotlib.axes.Axes.annotate" title="matplotlib.axes.Axes.annotate"><code class="xref py py-obj docutils literal notranslate"><span class="pre">annotate</span></code></a> for available coordinate systems.</p>
<p>An arrow connecting <em>xy</em> to <em>xytext</em> can be optionally drawn by
specifying the <em>arrowprops</em> argument. To draw only an arrow, use
empty string as the first argument.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ax</span><span class="o">.</span><span class="n">annotate</span><span class="p">(</span><span class="s2">""</span><span class="p">,</span>
<span class="n">xy</span><span class="o">=</span><span class="p">(</span><span class="mf">0.2</span><span class="p">,</span> <span class="mf">0.2</span><span class="p">),</span> <span class="n">xycoords</span><span class="o">=</span><span class="s1">'data'</span><span class="p">,</span>
<span class="n">xytext</span><span class="o">=</span><span class="p">(</span><span class="mf">0.8</span><span class="p">,</span> <span class="mf">0.8</span><span class="p">),</span> <span class="n">textcoords</span><span class="o">=</span><span class="s1">'data'</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">arrowstyle</span><span class="o">=</span><span class="s2">"->"</span><span class="p">,</span>
<span class="n">connectionstyle</span><span class="o">=</span><span class="s2">"arc3"</span><span class="p">),</span>
<span class="p">)</span>
</pre></div>
</div>
<figure class="align-center">
<a class="reference external image-reference" href="../../gallery/userdemo/annotate_simple01.html"><img alt="../../_images/sphx_glr_annotate_simple01_001.png" src="../../_images/sphx_glr_annotate_simple01_001.png" /></a>
</figure>
<p>The arrow is drawn as follows:</p>
<ol class="arabic simple">
<li><p>A path connecting the two points is created, as specified by the
<em>connectionstyle</em> parameter.</p></li>
<li><p>The path is clipped to avoid patches <em>patchA</em> and <em>patchB</em>, if these are
set.</p></li>
<li><p>The path is further shrunk by <em>shrinkA</em> and <em>shrinkB</em> (in pixels).</p></li>
<li><p>The path is transmuted to an arrow patch, as specified by the <em>arrowstyle</em>
parameter.</p></li>
</ol>
<figure class="align-center">
<a class="reference external image-reference" href="../../gallery/userdemo/annotate_explain.html"><img alt="../../_images/sphx_glr_annotate_explain_001.png" src="../../_images/sphx_glr_annotate_explain_001.png" /></a>
</figure>
<p>The creation of the connecting path between two points is controlled by
<code class="docutils literal notranslate"><span class="pre">connectionstyle</span></code> key and the following styles are available.</p>
<blockquote>
<div><table class="table">
<thead>
<tr class="row-odd"><th class="head"><p>Name</p></th>
<th class="head"><p>Attrs</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">angle</span></code></p></td>
<td><p>angleA=90,angleB=0,rad=0.0</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">angle3</span></code></p></td>
<td><p>angleA=90,angleB=0</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">arc</span></code></p></td>
<td><p>angleA=0,angleB=0,armA=None,armB=None,rad=0.0</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">arc3</span></code></p></td>
<td><p>rad=0.0</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">bar</span></code></p></td>
<td><p>armA=0.0,armB=0.0,fraction=0.3,angle=None</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<p>Note that "3" in <code class="docutils literal notranslate"><span class="pre">angle3</span></code> and <code class="docutils literal notranslate"><span class="pre">arc3</span></code> is meant to indicate that the
resulting path is a quadratic spline segment (three control
points). As will be discussed below, some arrow style options can only
be used when the connecting path is a quadratic spline.</p>
<p>The behavior of each connection style is (limitedly) demonstrated in the
example below. (Warning: The behavior of the <code class="docutils literal notranslate"><span class="pre">bar</span></code> style is currently not
well defined, it may be changed in the future).</p>
<figure class="align-center">
<a class="reference external image-reference" href="../../gallery/userdemo/connectionstyle_demo.html"><img alt="../../_images/sphx_glr_connectionstyle_demo_001.png" src="../../_images/sphx_glr_connectionstyle_demo_001.png" /></a>
</figure>
<p>The connecting path (after clipping and shrinking) is then mutated to
an arrow patch, according to the given <code class="docutils literal notranslate"><span class="pre">arrowstyle</span></code>.</p>
<blockquote>
<div><table class="table">
<thead>
<tr class="row-odd"><th class="head"><p>Name</p></th>
<th class="head"><p>Attrs</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">-</span></code></p></td>
<td><p>None</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">-></span></code></p></td>
<td><p>head_length=0.4,head_width=0.2</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">-[</span></code></p></td>
<td><p>widthB=1.0,lengthB=0.2,angleB=None</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">|-|</span></code></p></td>
<td><p>widthA=1.0,widthB=1.0</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">-|></span></code></p></td>
<td><p>head_length=0.4,head_width=0.2</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre"><-</span></code></p></td>
<td><p>head_length=0.4,head_width=0.2</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre"><-></span></code></p></td>
<td><p>head_length=0.4,head_width=0.2</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre"><|-</span></code></p></td>
<td><p>head_length=0.4,head_width=0.2</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre"><|-|></span></code></p></td>
<td><p>head_length=0.4,head_width=0.2</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">fancy</span></code></p></td>
<td><p>head_length=0.4,head_width=0.4,tail_width=0.4</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">simple</span></code></p></td>
<td><p>head_length=0.5,head_width=0.5,tail_width=0.2</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">wedge</span></code></p></td>
<td><p>tail_width=0.3,shrink_factor=0.5</p></td>
</tr>
</tbody>
</table>
</div></blockquote>
<figure class="align-center">
<a class="reference external image-reference" href="../../gallery/text_labels_and_annotations/fancyarrow_demo.html"><img alt="../../_images/sphx_glr_fancyarrow_demo_001.png" src="../../_images/sphx_glr_fancyarrow_demo_001.png" /></a>
</figure>
<p>Some arrowstyles only work with connection styles that generate a
quadratic-spline segment. They are <code class="docutils literal notranslate"><span class="pre">fancy</span></code>, <code class="docutils literal notranslate"><span class="pre">simple</span></code>, and <code class="docutils literal notranslate"><span class="pre">wedge</span></code>.
For these arrow styles, you must use the "angle3" or "arc3" connection
style.</p>
<p>If the annotation string is given, the patchA is set to the bbox patch
of the text by default.</p>
<figure class="align-center">
<a class="reference external image-reference" href="../../gallery/userdemo/annotate_simple02.html"><img alt="../../_images/sphx_glr_annotate_simple02_001.png" src="../../_images/sphx_glr_annotate_simple02_001.png" /></a>
</figure>
<p>As with <a class="reference internal" href="../../api/_as_gen/matplotlib.axes.Axes.text.html#matplotlib.axes.Axes.text" title="matplotlib.axes.Axes.text"><code class="xref py py-obj docutils literal notranslate"><span class="pre">text</span></code></a>, a box around the text can be drawn using the <em>bbox</em>
argument.</p>
<figure class="align-center">
<a class="reference external image-reference" href="../../gallery/userdemo/annotate_simple03.html"><img alt="../../_images/sphx_glr_annotate_simple03_001.png" src="../../_images/sphx_glr_annotate_simple03_001.png" /></a>
</figure>
<p>By default, the starting point is set to the center of the text
extent. This can be adjusted with <code class="docutils literal notranslate"><span class="pre">relpos</span></code> key value. The values
are normalized to the extent of the text. For example, (0, 0) means
lower-left corner and (1, 1) means top-right.</p>
<figure class="align-center">
<a class="reference external image-reference" href="../../gallery/userdemo/annotate_simple04.html"><img alt="../../_images/sphx_glr_annotate_simple04_001.png" src="../../_images/sphx_glr_annotate_simple04_001.png" /></a>
</figure>
</section>
<section id="placing-artist-at-anchored-axes-locations">
<h3><a class="toc-backref" href="#id6" role="doc-backlink">Placing Artist at anchored Axes locations</a><a class="headerlink" href="#placing-artist-at-anchored-axes-locations" title="Permalink to this heading">#</a></h3>
<p>There are classes of artists that can be placed at an anchored
location in the Axes. A common example is the legend. This type
of artist can be created by using the <a class="reference internal" href="../../api/offsetbox_api.html#matplotlib.offsetbox.OffsetBox" title="matplotlib.offsetbox.OffsetBox"><code class="xref py py-obj docutils literal notranslate"><span class="pre">OffsetBox</span></code></a> class. A few
predefined classes are available in <a class="reference internal" href="../../api/offsetbox_api.html#module-matplotlib.offsetbox" title="matplotlib.offsetbox"><code class="xref py py-mod docutils literal notranslate"><span class="pre">matplotlib.offsetbox</span></code></a> and in
<a class="reference internal" href="../../api/_as_gen/mpl_toolkits.axes_grid1.anchored_artists.html#module-mpl_toolkits.axes_grid1.anchored_artists" title="mpl_toolkits.axes_grid1.anchored_artists"><code class="xref py py-mod docutils literal notranslate"><span class="pre">mpl_toolkits.axes_grid1.anchored_artists</span></code></a>.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">matplotlib.offsetbox</span> <span class="kn">import</span> <a href="../../api/offsetbox_api.html#matplotlib.offsetbox.AnchoredText" title="matplotlib.offsetbox.AnchoredText" class="sphx-glr-backref-module-matplotlib-offsetbox sphx-glr-backref-type-py-class"><span class="n">AnchoredText</span></a>
<a href="../../api/figure_api.html#matplotlib.figure.Figure" title="matplotlib.figure.Figure" class="sphx-glr-backref-module-matplotlib-figure sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">fig</span></a><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <a href="../../api/_as_gen/matplotlib.pyplot.subplots.html#matplotlib.pyplot.subplots" title="matplotlib.pyplot.subplots" class="sphx-glr-backref-module-matplotlib-pyplot sphx-glr-backref-type-py-function"><span class="n">plt</span><span class="o">.</span><span class="n">subplots</span></a><span class="p">()</span>
<a href="../../api/offsetbox_api.html#matplotlib.offsetbox.AnchoredText" title="matplotlib.offsetbox.AnchoredText" class="sphx-glr-backref-module-matplotlib-offsetbox sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">at</span></a> <span class="o">=</span> <a href="../../api/offsetbox_api.html#matplotlib.offsetbox.AnchoredText" title="matplotlib.offsetbox.AnchoredText" class="sphx-glr-backref-module-matplotlib-offsetbox sphx-glr-backref-type-py-class"><span class="n">AnchoredText</span></a><span class="p">(</span>
<span class="s2">"Figure 1a"</span><span class="p">,</span> <span class="n">prop</span><span class="o">=</span><span class="nb">dict</span><span class="p">(</span><span class="n">size</span><span class="o">=</span><span class="mi">15</span><span class="p">),</span> <span class="n">frameon</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">loc</span><span class="o">=</span><span class="s1">'upper left'</span><span class="p">)</span>
<a href="../../api/_as_gen/matplotlib.patches.FancyBboxPatch.html#matplotlib.patches.FancyBboxPatch.set_boxstyle" title="matplotlib.patches.FancyBboxPatch.set_boxstyle" class="sphx-glr-backref-module-matplotlib-patches sphx-glr-backref-type-py-method"><span class="n">at</span><span class="o">.</span><span class="n">patch</span><span class="o">.</span><span class="n">set_boxstyle</span></a><span class="p">(</span><span class="s2">"round,pad=0.,rounding_size=0.2"</span><span class="p">)</span>
<a href="../../api/_as_gen/matplotlib.axes.Axes.add_artist.html#matplotlib.axes.Axes.add_artist" title="matplotlib.axes.Axes.add_artist" class="sphx-glr-backref-module-matplotlib-axes sphx-glr-backref-type-py-method"><span class="n">ax</span><span class="o">.</span><span class="n">add_artist</span></a><span class="p">(</span><a href="../../api/offsetbox_api.html#matplotlib.offsetbox.AnchoredText" title="matplotlib.offsetbox.AnchoredText" class="sphx-glr-backref-module-matplotlib-offsetbox sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">at</span></a><span class="p">)</span>
</pre></div>
</div>
<img src="../../_images/sphx_glr_annotations_001.png" srcset="../../_images/sphx_glr_annotations_001.png, ../../_images/sphx_glr_annotations_001_2_0x.png 2.0x" alt="annotations" class = "sphx-glr-single-img"/><p>The <em>loc</em> keyword has same meaning as in the legend command.</p>
<p>A simple application is when the size of the artist (or collection of
artists) is known in pixel size during the time of creation. For
example, If you want to draw a circle with fixed size of 20 pixel x 20
pixel (radius = 10 pixel), you can utilize
<a class="reference internal" href="../../api/_as_gen/mpl_toolkits.axes_grid1.anchored_artists.AnchoredDrawingArea.html#mpl_toolkits.axes_grid1.anchored_artists.AnchoredDrawingArea" title="mpl_toolkits.axes_grid1.anchored_artists.AnchoredDrawingArea"><code class="xref py py-obj docutils literal notranslate"><span class="pre">AnchoredDrawingArea</span></code></a>. The instance
is created with a size of the drawing area (in pixels), and arbitrary artists
can added to the drawing area. Note that the extents of the artists that are
added to the drawing area are not related to the placement of the drawing
area itself. Only the initial size matters.</p>
<p>The artists that are added to the drawing area should not have a
transform set (it will be overridden) and the dimensions of those
artists are interpreted as a pixel coordinate, i.e., the radius of the
circles in above example are 10 pixels and 5 pixels, respectively.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">matplotlib.patches</span> <span class="kn">import</span> <a href="../../api/_as_gen/matplotlib.patches.Circle.html#matplotlib.patches.Circle" title="matplotlib.patches.Circle" class="sphx-glr-backref-module-matplotlib-patches sphx-glr-backref-type-py-class"><span class="n">Circle</span></a>
<span class="kn">from</span> <span class="nn">mpl_toolkits.axes_grid1.anchored_artists</span> <span class="kn">import</span> <a href="../../api/offsetbox_api.html#matplotlib.offsetbox.AnchoredOffsetbox" title="matplotlib.offsetbox.AnchoredOffsetbox" class="sphx-glr-backref-module-matplotlib-offsetbox sphx-glr-backref-type-py-class"><span class="n">AnchoredDrawingArea</span></a>
<a href="../../api/figure_api.html#matplotlib.figure.Figure" title="matplotlib.figure.Figure" class="sphx-glr-backref-module-matplotlib-figure sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">fig</span></a><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <a href="../../api/_as_gen/matplotlib.pyplot.subplots.html#matplotlib.pyplot.subplots" title="matplotlib.pyplot.subplots" class="sphx-glr-backref-module-matplotlib-pyplot sphx-glr-backref-type-py-function"><span class="n">plt</span><span class="o">.</span><span class="n">subplots</span></a><span class="p">()</span>
<span class="n">ada</span> <span class="o">=</span> <a href="../../api/offsetbox_api.html#matplotlib.offsetbox.AnchoredOffsetbox" title="matplotlib.offsetbox.AnchoredOffsetbox" class="sphx-glr-backref-module-matplotlib-offsetbox sphx-glr-backref-type-py-class"><span class="n">AnchoredDrawingArea</span></a><span class="p">(</span><span class="mi">40</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span>
<span class="n">loc</span><span class="o">=</span><span class="s1">'upper right'</span><span class="p">,</span> <span class="n">pad</span><span class="o">=</span><span class="mf">0.</span><span class="p">,</span> <span class="n">frameon</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
<a href="../../api/_as_gen/matplotlib.patches.Circle.html#matplotlib.patches.Circle" title="matplotlib.patches.Circle" class="sphx-glr-backref-module-matplotlib-patches sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">p1</span></a> <span class="o">=</span> <a href="../../api/_as_gen/matplotlib.patches.Circle.html#matplotlib.patches.Circle" title="matplotlib.patches.Circle" class="sphx-glr-backref-module-matplotlib-patches sphx-glr-backref-type-py-class"><span class="n">Circle</span></a><span class="p">((</span><span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="mi">10</span><span class="p">)</span>
<a href="../../api/offsetbox_api.html#matplotlib.offsetbox.DrawingArea.add_artist" title="matplotlib.offsetbox.DrawingArea.add_artist" class="sphx-glr-backref-module-matplotlib-offsetbox sphx-glr-backref-type-py-method"><span class="n">ada</span><span class="o">.</span><span class="n">drawing_area</span><span class="o">.</span><span class="n">add_artist</span></a><span class="p">(</span><a href="../../api/_as_gen/matplotlib.patches.Circle.html#matplotlib.patches.Circle" title="matplotlib.patches.Circle" class="sphx-glr-backref-module-matplotlib-patches sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">p1</span></a><span class="p">)</span>
<a href="../../api/_as_gen/matplotlib.patches.Circle.html#matplotlib.patches.Circle" title="matplotlib.patches.Circle" class="sphx-glr-backref-module-matplotlib-patches sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">p2</span></a> <span class="o">=</span> <a href="../../api/_as_gen/matplotlib.patches.Circle.html#matplotlib.patches.Circle" title="matplotlib.patches.Circle" class="sphx-glr-backref-module-matplotlib-patches sphx-glr-backref-type-py-class"><span class="n">Circle</span></a><span class="p">((</span><span class="mi">30</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="mi">5</span><span class="p">,</span> <span class="n">fc</span><span class="o">=</span><span class="s2">"r"</span><span class="p">)</span>
<a href="../../api/offsetbox_api.html#matplotlib.offsetbox.DrawingArea.add_artist" title="matplotlib.offsetbox.DrawingArea.add_artist" class="sphx-glr-backref-module-matplotlib-offsetbox sphx-glr-backref-type-py-method"><span class="n">ada</span><span class="o">.</span><span class="n">drawing_area</span><span class="o">.</span><span class="n">add_artist</span></a><span class="p">(</span><a href="../../api/_as_gen/matplotlib.patches.Circle.html#matplotlib.patches.Circle" title="matplotlib.patches.Circle" class="sphx-glr-backref-module-matplotlib-patches sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">p2</span></a><span class="p">)</span>
<a href="../../api/_as_gen/matplotlib.axes.Axes.add_artist.html#matplotlib.axes.Axes.add_artist" title="matplotlib.axes.Axes.add_artist" class="sphx-glr-backref-module-matplotlib-axes sphx-glr-backref-type-py-method"><span class="n">ax</span><span class="o">.</span><span class="n">add_artist</span></a><span class="p">(</span><span class="n">ada</span><span class="p">)</span>
</pre></div>
</div>
<img src="../../_images/sphx_glr_annotations_002.png" srcset="../../_images/sphx_glr_annotations_002.png, ../../_images/sphx_glr_annotations_002_2_0x.png 2.0x" alt="annotations" class = "sphx-glr-single-img"/><p>Sometimes, you want your artists to scale with the data coordinate (or
coordinates other than canvas pixels). You can use
<a class="reference internal" href="../../api/_as_gen/mpl_toolkits.axes_grid1.anchored_artists.AnchoredAuxTransformBox.html#mpl_toolkits.axes_grid1.anchored_artists.AnchoredAuxTransformBox" title="mpl_toolkits.axes_grid1.anchored_artists.AnchoredAuxTransformBox"><code class="xref py py-obj docutils literal notranslate"><span class="pre">AnchoredAuxTransformBox</span></code></a> class.
This is similar to
<a class="reference internal" href="../../api/_as_gen/mpl_toolkits.axes_grid1.anchored_artists.AnchoredDrawingArea.html#mpl_toolkits.axes_grid1.anchored_artists.AnchoredDrawingArea" title="mpl_toolkits.axes_grid1.anchored_artists.AnchoredDrawingArea"><code class="xref py py-obj docutils literal notranslate"><span class="pre">AnchoredDrawingArea</span></code></a> except that
the extent of the artist is determined during the drawing time respecting the
specified transform.</p>
<p>The ellipse in the example below will have width and height
corresponding to 0.1 and 0.4 in data coordinates and will be
automatically scaled when the view limits of the axes change.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">matplotlib.patches</span> <span class="kn">import</span> <a href="../../api/_as_gen/matplotlib.patches.Ellipse.html#matplotlib.patches.Ellipse" title="matplotlib.patches.Ellipse" class="sphx-glr-backref-module-matplotlib-patches sphx-glr-backref-type-py-class"><span class="n">Ellipse</span></a>
<span class="kn">from</span> <span class="nn">mpl_toolkits.axes_grid1.anchored_artists</span> <span class="kn">import</span> <a href="../../api/offsetbox_api.html#matplotlib.offsetbox.AnchoredOffsetbox" title="matplotlib.offsetbox.AnchoredOffsetbox" class="sphx-glr-backref-module-matplotlib-offsetbox sphx-glr-backref-type-py-class"><span class="n">AnchoredAuxTransformBox</span></a>
<a href="../../api/figure_api.html#matplotlib.figure.Figure" title="matplotlib.figure.Figure" class="sphx-glr-backref-module-matplotlib-figure sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">fig</span></a><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <a href="../../api/_as_gen/matplotlib.pyplot.subplots.html#matplotlib.pyplot.subplots" title="matplotlib.pyplot.subplots" class="sphx-glr-backref-module-matplotlib-pyplot sphx-glr-backref-type-py-function"><span class="n">plt</span><span class="o">.</span><span class="n">subplots</span></a><span class="p">()</span>
<span class="n">box</span> <span class="o">=</span> <a href="../../api/offsetbox_api.html#matplotlib.offsetbox.AnchoredOffsetbox" title="matplotlib.offsetbox.AnchoredOffsetbox" class="sphx-glr-backref-module-matplotlib-offsetbox sphx-glr-backref-type-py-class"><span class="n">AnchoredAuxTransformBox</span></a><span class="p">(</span><a href="../../api/transformations.html#matplotlib.transforms.CompositeGenericTransform" title="matplotlib.transforms.CompositeGenericTransform" class="sphx-glr-backref-module-matplotlib-transforms sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">ax</span><span class="o">.</span><span class="n">transData</span></a><span class="p">,</span> <span class="n">loc</span><span class="o">=</span><span class="s1">'upper left'</span><span class="p">)</span>
<a href="../../api/_as_gen/matplotlib.patches.Ellipse.html#matplotlib.patches.Ellipse" title="matplotlib.patches.Ellipse" class="sphx-glr-backref-module-matplotlib-patches sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">el</span></a> <span class="o">=</span> <a href="../../api/_as_gen/matplotlib.patches.Ellipse.html#matplotlib.patches.Ellipse" title="matplotlib.patches.Ellipse" class="sphx-glr-backref-module-matplotlib-patches sphx-glr-backref-type-py-class"><span class="n">Ellipse</span></a><span class="p">((</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">width</span><span class="o">=</span><span class="mf">0.1</span><span class="p">,</span> <span class="n">height</span><span class="o">=</span><span class="mf">0.4</span><span class="p">,</span> <span class="n">angle</span><span class="o">=</span><span class="mi">30</span><span class="p">)</span> <span class="c1"># in data coordinates!</span>
<a href="../../api/offsetbox_api.html#matplotlib.offsetbox.AuxTransformBox.add_artist" title="matplotlib.offsetbox.AuxTransformBox.add_artist" class="sphx-glr-backref-module-matplotlib-offsetbox sphx-glr-backref-type-py-method"><span class="n">box</span><span class="o">.</span><span class="n">drawing_area</span><span class="o">.</span><span class="n">add_artist</span></a><span class="p">(</span><a href="../../api/_as_gen/matplotlib.patches.Ellipse.html#matplotlib.patches.Ellipse" title="matplotlib.patches.Ellipse" class="sphx-glr-backref-module-matplotlib-patches sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">el</span></a><span class="p">)</span>
<a href="../../api/_as_gen/matplotlib.axes.Axes.add_artist.html#matplotlib.axes.Axes.add_artist" title="matplotlib.axes.Axes.add_artist" class="sphx-glr-backref-module-matplotlib-axes sphx-glr-backref-type-py-method"><span class="n">ax</span><span class="o">.</span><span class="n">add_artist</span></a><span class="p">(</span><span class="n">box</span><span class="p">)</span>
</pre></div>
</div>
<img src="../../_images/sphx_glr_annotations_003.png" srcset="../../_images/sphx_glr_annotations_003.png, ../../_images/sphx_glr_annotations_003_2_0x.png 2.0x" alt="annotations" class = "sphx-glr-single-img"/><p>As in the legend, the bbox_to_anchor argument can be set. Using the
HPacker and VPacker, you can have an arrangement(?) of artist as in the
legend (as a matter of fact, this is how the legend is created).</p>
<figure class="align-center">
<a class="reference external image-reference" href="../../gallery/userdemo/anchored_box04.html"><img alt="../../_images/sphx_glr_anchored_box04_001.png" src="../../_images/sphx_glr_anchored_box04_001.png" /></a>
</figure>
<p>Note that unlike the legend, the <code class="docutils literal notranslate"><span class="pre">bbox_transform</span></code> is set
to IdentityTransform by default.</p>
</section>
<section id="coordinate-systems-for-annotations">
<h3><a class="toc-backref" href="#id7" role="doc-backlink">Coordinate systems for Annotations</a><a class="headerlink" href="#coordinate-systems-for-annotations" title="Permalink to this heading">#</a></h3>
<p>Matplotlib Annotations support several types of coordinates. Some are
described in <a class="reference internal" href="#annotations-tutorial"><span class="std std-ref">Basic annotation</span></a>; more advanced options are</p>
<ol class="arabic">
<li><p>A <a class="reference internal" href="../../api/transformations.html#matplotlib.transforms.Transform" title="matplotlib.transforms.Transform"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Transform</span></code></a> instance. For example,</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ax</span><span class="o">.</span><span class="n">annotate</span><span class="p">(</span><span class="s2">"Test"</span><span class="p">,</span> <span class="n">xy</span><span class="o">=</span><span class="p">(</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">),</span> <span class="n">xycoords</span><span class="o">=</span><span class="n">ax</span><span class="o">.</span><span class="n">transAxes</span><span class="p">)</span>
</pre></div>
</div>
<p>is identical to</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ax</span><span class="o">.</span><span class="n">annotate</span><span class="p">(</span><span class="s2">"Test"</span><span class="p">,</span> <span class="n">xy</span><span class="o">=</span><span class="p">(</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">),</span> <span class="n">xycoords</span><span class="o">=</span><span class="s2">"axes fraction"</span><span class="p">)</span>
</pre></div>
</div>
<p>This allows annotating a point in another axes:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><a href="../../api/figure_api.html#matplotlib.figure.Figure" title="matplotlib.figure.Figure" class="sphx-glr-backref-module-matplotlib-figure sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">fig</span></a><span class="p">,</span> <span class="p">(</span><span class="n">ax1</span><span class="p">,</span> <span class="n">ax2</span><span class="p">)</span> <span class="o">=</span> <a href="../../api/_as_gen/matplotlib.pyplot.subplots.html#matplotlib.pyplot.subplots" title="matplotlib.pyplot.subplots" class="sphx-glr-backref-module-matplotlib-pyplot sphx-glr-backref-type-py-function"><span class="n">plt</span><span class="o">.</span><span class="n">subplots</span></a><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
<span class="n">ax2</span><span class="o">.</span><span class="n">annotate</span><span class="p">(</span><span class="s2">"Test"</span><span class="p">,</span> <span class="n">xy</span><span class="o">=</span><span class="p">(</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">),</span> <span class="n">xycoords</span><span class="o">=</span><span class="n">ax1</span><span class="o">.</span><span class="n">transData</span><span class="p">,</span>
<span class="n">xytext</span><span class="o">=</span><span class="p">(</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">),</span> <span class="n">textcoords</span><span class="o">=</span><span class="n">ax2</span><span class="o">.</span><span class="n">transData</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">arrowstyle</span><span class="o">=</span><span class="s2">"->"</span><span class="p">))</span>
</pre></div>
</div>
</li>
<li><p>An <a class="reference internal" href="../../api/artist_api.html#matplotlib.artist.Artist" title="matplotlib.artist.Artist"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Artist</span></code></a> instance. The <em>xy</em> value (or <em>xytext</em>) is interpreted as a
fractional coordinate of the bbox (return value of <em>get_window_extent</em>) of
the artist:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">an1</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">annotate</span><span class="p">(</span><span class="s2">"Test 1"</span><span class="p">,</span> <span class="n">xy</span><span class="o">=</span><span class="p">(</span><span class="mf">0.5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">),</span> <span class="n">xycoords</span><span class="o">=</span><span class="s2">"data"</span><span class="p">,</span>
<span class="n">va</span><span class="o">=</span><span class="s2">"center"</span><span class="p">,</span> <span class="n">ha</span><span class="o">=</span><span class="s2">"center"</span><span class="p">,</span>
<span class="n">bbox</span><span class="o">=</span><span class="nb">dict</span><span class="p">(</span><span class="n">boxstyle</span><span class="o">=</span><span class="s2">"round"</span><span class="p">,</span> <span class="n">fc</span><span class="o">=</span><span class="s2">"w"</span><span class="p">))</span>
<span class="n">an2</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">annotate</span><span class="p">(</span><span class="s2">"Test 2"</span><span class="p">,</span> <span class="n">xy</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">),</span> <span class="n">xycoords</span><span class="o">=</span><span class="n">an1</span><span class="p">,</span> <span class="c1"># (1, 0.5) of the an1's bbox</span>
<span class="n">xytext</span><span class="o">=</span><span class="p">(</span><span class="mi">30</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">textcoords</span><span class="o">=</span><span class="s2">"offset points"</span><span class="p">,</span>
<span class="n">va</span><span class="o">=</span><span class="s2">"center"</span><span class="p">,</span> <span class="n">ha</span><span class="o">=</span><span class="s2">"left"</span><span class="p">,</span>
<span class="n">bbox</span><span class="o">=</span><span class="nb">dict</span><span class="p">(</span><span class="n">boxstyle</span><span class="o">=</span><span class="s2">"round"</span><span class="p">,</span> <span class="n">fc</span><span class="o">=</span><span class="s2">"w"</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">arrowstyle</span><span class="o">=</span><span class="s2">"->"</span><span class="p">))</span>
</pre></div>
</div>
<figure class="align-center">
<a class="reference external image-reference" href="../../gallery/userdemo/annotate_simple_coord01.html"><img alt="../../_images/sphx_glr_annotate_simple_coord01_001.png" src="../../_images/sphx_glr_annotate_simple_coord01_001.png" /></a>
</figure>
<p>Note that you must ensure that the extent of the coordinate artist (<em>an1</em> in
above example) is determined before <em>an2</em> gets drawn. Usually, this means
that <em>an2</em> needs to be drawn after <em>an1</em>.</p>
</li>
<li><p>A callable object that takes the renderer instance as single argument, and
returns either a <a class="reference internal" href="../../api/transformations.html#matplotlib.transforms.Transform" title="matplotlib.transforms.Transform"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Transform</span></code></a> or a <a class="reference internal" href="../../api/transformations.html#matplotlib.transforms.BboxBase" title="matplotlib.transforms.BboxBase"><code class="xref py py-obj docutils literal notranslate"><span class="pre">BboxBase</span></code></a>. The return value is then
handled as in (1), for transforms, or in (2), for bboxes. For example,</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">an2</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">annotate</span><span class="p">(</span><span class="s2">"Test 2"</span><span class="p">,</span> <span class="n">xy</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">),</span> <span class="n">xycoords</span><span class="o">=</span><span class="n">an1</span><span class="p">,</span>
<span class="n">xytext</span><span class="o">=</span><span class="p">(</span><span class="mi">30</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">textcoords</span><span class="o">=</span><span class="s2">"offset points"</span><span class="p">)</span>
</pre></div>
</div>
<p>is identical to:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">an2</span> <span class="o">=</span> <span class="n">ax</span><span class="o">.</span><span class="n">annotate</span><span class="p">(</span><span class="s2">"Test 2"</span><span class="p">,</span> <span class="n">xy</span><span class="o">=</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">),</span> <span class="n">xycoords</span><span class="o">=</span><span class="n">an1</span><span class="o">.</span><span class="n">get_window_extent</span><span class="p">,</span>
<span class="n">xytext</span><span class="o">=</span><span class="p">(</span><span class="mi">30</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="n">textcoords</span><span class="o">=</span><span class="s2">"offset points"</span><span class="p">)</span>
</pre></div>
</div>
</li>
<li><p>A pair of coordinate specifications -- the first for the x-coordinate, and
the second is for the y-coordinate; e.g.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">annotate</span><span class="p">(</span><span class="s2">"Test"</span><span class="p">,</span> <span class="n">xy</span><span class="o">=</span><span class="p">(</span><span class="mf">0.5</span><span class="p">,</span> <span class="mi">1</span><span class="p">),</span> <span class="n">xycoords</span><span class="o">=</span><span class="p">(</span><span class="s2">"data"</span><span class="p">,</span> <span class="s2">"axes fraction"</span><span class="p">))</span>
</pre></div>
</div>
<p>Here, 0.5 is in data coordinates, and 1 is in normalized axes coordinates.
Each of the coordinate specifications can also be an artist or a transform.
For example,</p>
<figure class="align-center">
<a class="reference external image-reference" href="../../gallery/userdemo/annotate_simple_coord02.html"><img alt="../../_images/sphx_glr_annotate_simple_coord02_001.png" src="../../_images/sphx_glr_annotate_simple_coord02_001.png" /></a>
</figure>
</li>
<li><p>Sometimes, you want your annotation with some "offset points", not from the
annotated point but from some other point. <a class="reference internal" href="../../api/text_api.html#matplotlib.text.OffsetFrom" title="matplotlib.text.OffsetFrom"><code class="xref py py-obj docutils literal notranslate"><span class="pre">text.OffsetFrom</span></code></a> is a helper
for such cases.</p>
<figure class="align-center">
<a class="reference external image-reference" href="../../gallery/userdemo/annotate_simple_coord03.html"><img alt="../../_images/sphx_glr_annotate_simple_coord03_001.png" src="../../_images/sphx_glr_annotate_simple_coord03_001.png" /></a>
</figure>
<p>You may take a look at this example
<a class="reference internal" href="../../gallery/text_labels_and_annotations/annotation_demo.html"><span class="doc">Annotating Plots</span></a>.</p>
</li>
</ol>