-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfaq.html
1010 lines (799 loc) · 65.3 KB
/
faq.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
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" data-content_root="../" >
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Frequently Asked Questions — Matplotlib 3.11.0.dev711+g492a478bfe documentation</title>
<script data-cfasync="false">
document.documentElement.dataset.mode = localStorage.getItem("mode") || "";
document.documentElement.dataset.theme = localStorage.getItem("theme") || "";
</script>
<!-- Loaded before other Sphinx assets -->
<link href="../_static/styles/theme.css?digest=dfe6caa3a7d634c4db9b" rel="stylesheet" />
<link href="../_static/styles/bootstrap.css?digest=dfe6caa3a7d634c4db9b" rel="stylesheet" />
<link href="../_static/styles/pydata-sphinx-theme.css?digest=dfe6caa3a7d634c4db9b" rel="stylesheet" />
<link href="../_static/vendor/fontawesome/6.5.2/css/all.min.css?digest=dfe6caa3a7d634c4db9b" rel="stylesheet" />
<link rel="preload" as="font" type="font/woff2" crossorigin href="../_static/vendor/fontawesome/6.5.2/webfonts/fa-solid-900.woff2" />
<link rel="preload" as="font" type="font/woff2" crossorigin href="../_static/vendor/fontawesome/6.5.2/webfonts/fa-brands-400.woff2" />
<link rel="preload" as="font" type="font/woff2" crossorigin href="../_static/vendor/fontawesome/6.5.2/webfonts/fa-regular-400.woff2" />
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=03e43079" />
<link rel="stylesheet" type="text/css" href="../_static/css/style.css?v=f16eb9d3" />
<link rel="stylesheet" type="text/css" href="../_static/graphviz.css?v=4ae1632d" />
<link rel="stylesheet" type="text/css" href="../_static/plot_directive.css" />
<link rel="stylesheet" type="text/css" href="../_static/copybutton.css?v=76b2166b" />
<link rel="stylesheet" type="text/css" href="../_static/sg_gallery.css?v=d2d258e8" />
<link rel="stylesheet" type="text/css" href="../_static/sg_gallery-binder.css?v=f4aeca0c" />
<link rel="stylesheet" type="text/css" href="../_static/sg_gallery-dataframe.css?v=2082cf3c" />
<link rel="stylesheet" type="text/css" href="../_static/sg_gallery-rendered-html.css?v=1277b6f3" />
<link rel="stylesheet" type="text/css" href="../_static/sphinx-design.min.css?v=95c83b7e" />
<link rel="stylesheet" type="text/css" href="../_static/mpl.css?v=459c4223" />
<!-- Pre-loaded scripts that we'll load fully later -->
<link rel="preload" as="script" href="../_static/scripts/bootstrap.js?digest=dfe6caa3a7d634c4db9b" />
<link rel="preload" as="script" href="../_static/scripts/pydata-sphinx-theme.js?digest=dfe6caa3a7d634c4db9b" />
<script src="../_static/vendor/fontawesome/6.5.2/js/all.min.js?digest=dfe6caa3a7d634c4db9b"></script>
<script src="../_static/documentation_options.js?v=bd5d8ceb"></script>
<script src="../_static/doctools.js?v=9bcbadda"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/clipboard.min.js?v=a7894cd8"></script>
<script src="../_static/copybutton.js?v=ccdb6887"></script>
<script src="../_static/design-tabs.js?v=f930bc37"></script>
<script data-domain="matplotlib.org" defer="defer" src="https://views.scientific-python.org/js/script.js"></script>
<script>DOCUMENTATION_OPTIONS.pagename = 'users/faq';</script>
<script>
DOCUMENTATION_OPTIONS.theme_version = '0.15.4';
DOCUMENTATION_OPTIONS.theme_switcher_json_url = 'https://matplotlib.org/devdocs/_static/switcher.json?v3.10.1-711-g492a478bfe';
DOCUMENTATION_OPTIONS.theme_switcher_version_match = 'dev';
DOCUMENTATION_OPTIONS.show_version_warning_banner = true;
</script>
<link rel="canonical" href="https://matplotlib.org/stable/users/faq.html" />
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Matplotlib 3.11.0.dev711+g492a478bfe documentation"
href="../_static/opensearch.xml"/>
<link rel="icon" href="../_static/favicon.ico"/>
<link rel="search" title="Search" href="../search.html" />
<link rel="next" title="Figures and backends" href="explain/figure/index.html" />
<link rel="prev" title="Using Matplotlib" href="index.html" />
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="docsearch:language" content="en"/>
<meta name="docbuild:last-update" content="Feb 27, 2025"/>
</head>
<body data-bs-spy="scroll" data-bs-target=".bd-toc-nav" data-offset="180" data-bs-root-margin="0px 0px -60%" data-default-mode="">
<div id="pst-skip-link" class="skip-link d-print-none"><a href="#main-content">Skip to main content</a></div>
<div id="pst-scroll-pixel-helper"></div>
<button type="button" class="btn rounded-pill" id="pst-back-to-top">
<i class="fa-solid fa-arrow-up"></i>Back to top</button>
<input type="checkbox"
class="sidebar-toggle"
id="pst-primary-sidebar-checkbox"/>
<label class="overlay overlay-primary" for="pst-primary-sidebar-checkbox"></label>
<input type="checkbox"
class="sidebar-toggle"
id="pst-secondary-sidebar-checkbox"/>
<label class="overlay overlay-secondary" for="pst-secondary-sidebar-checkbox"></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>
<div class="pst-async-banner-revealer d-none">
<aside id="bd-header-version-warning" class="d-none d-print-none" aria-label="Version warning"></aside>
</div>
<header class="bd-header navbar navbar-expand-lg bd-navbar d-print-none">
<div class="bd-header__inner bd-page-width">
<button class="pst-navbar-icon sidebar-toggle primary-toggle" aria-label="Site navigation">
<span class="fa-solid fa-bars"></span>
</button>
<div class="col-lg-3 navbar-header-items__start">
<div class="navbar-item">
<a class="navbar-brand logo" href="https://matplotlib.org/stable/">
<img src="../_static/logo_light.svg" class="logo__image only-light" alt="Matplotlib 3.11.0.dev711+g492a478bfe documentation - Home"/>
<script>document.write(`<img src="../_static/logo_dark.svg" class="logo__image only-dark" alt="Matplotlib 3.11.0.dev711+g492a478bfe documentation - Home"/>`);</script>
</a></div>
</div>
<div class="col-lg-9 navbar-header-items">
<div class="me-auto navbar-header-items__center">
<div class="navbar-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="index.html">User guide</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="../tutorials/index.html">Tutorials</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="../api/index.html">Reference</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="../devel/index.html">Contribute</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="release_notes.html">Releases</a>
</li>
</ul></div>
</div>
<div class="navbar-header-items__end">
<div class="navbar-item navbar-persistent--container">
<script>
document.write(`
<button class="btn btn-sm pst-navbar-icon search-button search-button__button" title="Search" aria-label="Search" data-bs-placement="bottom" data-bs-toggle="tooltip">
<i class="fa-solid fa-magnifying-glass fa-lg"></i>
</button>
`);
</script>
</div>
<div class="navbar-item">
<script>
document.write(`
<button class="btn btn-sm nav-link pst-navbar-icon theme-switch-button" title="light/dark" aria-label="light/dark" data-bs-placement="bottom" data-bs-toggle="tooltip">
<i class="theme-switch fa-solid fa-sun fa-lg" data-mode="light"></i>
<i class="theme-switch fa-solid fa-moon fa-lg" data-mode="dark"></i>
<i class="theme-switch fa-solid fa-circle-half-stroke fa-lg" data-mode="auto"></i>
</button>
`);
</script></div>
<div class="navbar-item">
<script>
document.write(`
<div class="version-switcher__container dropdown">
<button id="pst-version-switcher-button-2"
type="button"
class="version-switcher__button btn btn-sm dropdown-toggle"
data-bs-toggle="dropdown"
aria-haspopup="listbox"
aria-controls="pst-version-switcher-list-2"
aria-label="Version switcher list"
>
Choose version <!-- this text may get changed later by javascript -->
<span class="caret"></span>
</button>
<div id="pst-version-switcher-list-2"
class="version-switcher__menu dropdown-menu list-group-flush py-0"
role="listbox" aria-labelledby="pst-version-switcher-button-2">
<!-- dropdown will be populated by javascript on page load -->
</div>
</div>
`);
</script></div>
<div class="navbar-item"><ul class="navbar-icon-links"
aria-label="Icon Links">
<li class="nav-item">
<a href="https://gitter.im/matplotlib/matplotlib" title="Gitter" class="nav-link pst-navbar-icon" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><i class="fa-brands fa-gitter fa-lg" aria-hidden="true"></i>
<span class="sr-only">Gitter</span></a>
</li>
<li class="nav-item">
<a href="https://discourse.matplotlib.org" title="Discourse" class="nav-link pst-navbar-icon" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><i class="fa-brands fa-discourse fa-lg" aria-hidden="true"></i>
<span class="sr-only">Discourse</span></a>
</li>
<li class="nav-item">
<a href="https://github.com/matplotlib/matplotlib" title="GitHub" class="nav-link pst-navbar-icon" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><i class="fa-brands fa-github fa-lg" aria-hidden="true"></i>
<span class="sr-only">GitHub</span></a>
</li>
</ul></div>
</div>
</div>
<div class="navbar-persistent--mobile">
<script>
document.write(`
<button class="btn btn-sm pst-navbar-icon search-button search-button__button" title="Search" aria-label="Search" data-bs-placement="bottom" data-bs-toggle="tooltip">
<i class="fa-solid fa-magnifying-glass fa-lg"></i>
</button>
`);
</script>
</div>
<button class="pst-navbar-icon sidebar-toggle secondary-toggle" aria-label="On this page">
<span class="fa-solid fa-outdent"></span>
</button>
</div>
</header>
<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-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="index.html">User guide</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="../tutorials/index.html">Tutorials</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="../api/index.html">Reference</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="../devel/index.html">Contribute</a>
</li>
<li class="nav-item">
<a class="reference internal nav-link" href="release_notes.html">Releases</a>
</li>
</ul></div>
</div>
<div class="sidebar-header-items__end">
<div class="navbar-item">
<script>
document.write(`
<button class="btn btn-sm nav-link pst-navbar-icon theme-switch-button" title="light/dark" aria-label="light/dark" data-bs-placement="bottom" data-bs-toggle="tooltip">
<i class="theme-switch fa-solid fa-sun fa-lg" data-mode="light"></i>
<i class="theme-switch fa-solid fa-moon fa-lg" data-mode="dark"></i>
<i class="theme-switch fa-solid fa-circle-half-stroke fa-lg" data-mode="auto"></i>
</button>
`);
</script></div>
<div class="navbar-item">
<script>
document.write(`
<div class="version-switcher__container dropdown">
<button id="pst-version-switcher-button-3"
type="button"
class="version-switcher__button btn btn-sm dropdown-toggle"
data-bs-toggle="dropdown"
aria-haspopup="listbox"
aria-controls="pst-version-switcher-list-3"
aria-label="Version switcher list"
>
Choose version <!-- this text may get changed later by javascript -->
<span class="caret"></span>
</button>
<div id="pst-version-switcher-list-3"
class="version-switcher__menu dropdown-menu list-group-flush py-0"
role="listbox" aria-labelledby="pst-version-switcher-button-3">
<!-- dropdown will be populated by javascript on page load -->
</div>
</div>
`);
</script></div>
<div class="navbar-item"><ul class="navbar-icon-links"
aria-label="Icon Links">
<li class="nav-item">
<a href="https://gitter.im/matplotlib/matplotlib" title="Gitter" class="nav-link pst-navbar-icon" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><i class="fa-brands fa-gitter fa-lg" aria-hidden="true"></i>
<span class="sr-only">Gitter</span></a>
</li>
<li class="nav-item">
<a href="https://discourse.matplotlib.org" title="Discourse" class="nav-link pst-navbar-icon" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><i class="fa-brands fa-discourse fa-lg" aria-hidden="true"></i>
<span class="sr-only">Discourse</span></a>
</li>
<li class="nav-item">
<a href="https://github.com/matplotlib/matplotlib" title="GitHub" class="nav-link pst-navbar-icon" rel="noopener" target="_blank" data-bs-toggle="tooltip" data-bs-placement="bottom"><i class="fa-brands fa-github fa-lg" aria-hidden="true"></i>
<span class="sr-only">GitHub</span></a>
</li>
</ul></div>
</div>
</div>
<div class="sidebar-primary-items__start sidebar-primary__section">
<div class="sidebar-primary-item">
<nav class="bd-docs-nav bd-links"
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="nav bd-sidenav">
<li class="toctree-l1"><a class="reference internal" href="explain/quick_start.html">Quick start guide</a></li>
</ul>
<ul class="current nav bd-sidenav">
<li class="toctree-l1 current active"><a class="current reference internal" href="#">Frequently Asked Questions</a></li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1 has-children"><a class="reference internal" href="explain/figure/index.html">Figures and backends</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul>
<li class="toctree-l2"><a class="reference internal" href="explain/figure/figure_intro.html">Introduction to figures</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/figure/backends.html">Output backends</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/figure/api_interfaces.html">Matplotlib Application Interfaces (APIs)</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/figure/interactive.html">Interacting with figures</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/figure/interactive_guide.html">Interactive figures and asynchronous programming</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/figure/event_handling.html">Event handling</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/figure/writing_a_backend_pyplot_interface.html">Writing a backend -- the pyplot interface</a></li>
</ul>
</details></li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1 has-children"><a class="reference internal" href="explain/axes/index.html">Axes and subplots</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul>
<li class="toctree-l2"><a class="reference internal" href="explain/axes/axes_intro.html">Introduction to Axes (or Subplots)</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/axes/arranging_axes.html">Arranging multiple Axes in a Figure</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/axes/colorbar_placement.html">Placing colorbars</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/axes/autoscale.html">Axis autoscaling</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/axes/axes_scales.html">Axis scales</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/axes/axes_ticks.html">Axis ticks</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/axes/axes_units.html">Plotting dates and strings</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/axes/legend_guide.html">Legends</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/axes/mosaic.html">Subplot mosaic</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/axes/constrainedlayout_guide.html">Constrained layout guide</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/axes/tight_layout_guide.html">Tight layout guide (mildly discouraged)</a></li>
</ul>
</details></li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1 has-children"><a class="reference internal" href="explain/artists/index.html">Artists</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul>
<li class="toctree-l2"><a class="reference internal" href="explain/artists/artist_intro.html">Introduction to Artists</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/artists/color_cycle.html">Automated color cycle</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/artists/performance.html">Optimizing Artists for performance</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/artists/paths.html">Paths</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/artists/patheffects_guide.html">Path effects guide</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/artists/imshow_extent.html">Understanding the extent keyword argument of imshow</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/artists/transforms_tutorial.html">Transformations Tutorial</a></li>
</ul>
</details></li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1"><a class="reference internal" href="explain/customizing.html">Customizing Matplotlib with style sheets and rcParams</a></li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1 has-children"><a class="reference internal" href="explain/colors/index.html">Colors</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul>
<li class="toctree-l2"><a class="reference internal" href="explain/colors/colors.html">Specifying colors</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/colors/colorbar_only.html">Customized Colorbars Tutorial</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/colors/colormap-manipulation.html">Creating Colormaps in Matplotlib</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/colors/colormapnorms.html">Colormap normalization</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/colors/colormaps.html">Choosing Colormaps in Matplotlib</a></li>
</ul>
</details></li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1 has-children"><a class="reference internal" href="explain/text/index.html">Text</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul>
<li class="toctree-l2"><a class="reference internal" href="explain/text/text_intro.html">Text in Matplotlib</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/text/text_props.html">Text properties and layout</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/text/annotations.html">Annotations</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/text/fonts.html">Fonts in Matplotlib</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/text/mathtext.html">Writing mathematical expressions</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/text/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="explain/text/usetex.html">Text rendering with LaTeX</a></li>
</ul>
</details></li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1 has-children"><a class="reference internal" href="explain/animations/index.html">Animations using Matplotlib</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul>
<li class="toctree-l2"><a class="reference internal" href="explain/animations/animations.html">Animations using Matplotlib</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/animations/blitting.html">Faster rendering by using blitting</a></li>
</ul>
</details></li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1 has-children"><a class="reference internal" href="explain/toolkits/index.html">User Toolkits</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul>
<li class="toctree-l2"><a class="reference internal" href="explain/toolkits/axisartist.html">The axisartist toolkit</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/toolkits/axes_grid.html">The axes_grid1 toolkit</a></li>
<li class="toctree-l2"><a class="reference internal" href="explain/toolkits/mplot3d.html">The mplot3d toolkit</a></li>
</ul>
</details></li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1"><a class="reference internal" href="getting_started/index.html">Getting started</a></li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../install/index.html">Installation</a><details><summary><span class="toctree-toggle" role="presentation"><i class="fa-solid fa-chevron-down"></i></span></summary><ul>
<li class="toctree-l2"><a class="reference internal" href="../install/environment_variables_faq.html">Environment variables</a></li>
<li class="toctree-l2"><a class="reference internal" href="../install/dependencies.html">Dependencies</a></li>
</ul>
</details></li>
</ul>
</div>
</nav></div>
</div>
<div class="sidebar-primary-items__end sidebar-primary__section">
</div>
<div id="rtd-footer-container"></div>
</div>
<main id="main-content" class="bd-main" role="main">
<div class="bd-content">
<div class="bd-article-container">
<div class="bd-header-article d-print-none">
<div class="header-article-items header-article__inner">
<div class="header-article-items__start">
<div class="header-article-item">
<nav aria-label="Breadcrumb" class="d-print-none">
<ul class="bd-breadcrumbs">
<li class="breadcrumb-item breadcrumb-home">
<a href="../index.html" class="nav-link" aria-label="Home">
<i class="fa-solid fa-home"></i>
</a>
</li>
<li class="breadcrumb-item"><a href="index.html" class="nav-link">Using Matplotlib</a></li>
<li class="breadcrumb-item active" aria-current="page">Frequently...</li>
</ul>
</nav>
</div>
</div>
</div>
</div>
<div id="searchbox"></div>
<article class="bd-article">
<section id="frequently-asked-questions">
<span id="howto-faq"></span><h1>Frequently Asked Questions<a class="headerlink" href="#frequently-asked-questions" title="Link to this heading">#</a></h1>
<section id="i-don-t-see-a-figure-window">
<span id="how-do-no-figure"></span><h2>I don't see a figure window<a class="headerlink" href="#i-don-t-see-a-figure-window" title="Link to this heading">#</a></h2>
<p>Please see <a class="reference internal" href="explain/figure/backends.html#figures-not-showing"><span class="std std-ref">Debugging the figure windows not showing</span></a>.</p>
</section>
<section id="why-do-i-have-so-many-ticks-and-or-why-are-they-out-of-order">
<span id="how-to-too-many-ticks"></span><h2>Why do I have so many ticks, and/or why are they out of order?<a class="headerlink" href="#why-do-i-have-so-many-ticks-and-or-why-are-they-out-of-order" title="Link to this heading">#</a></h2>
<p>One common cause for unexpected tick behavior is passing a <em>list of strings
instead of numbers or datetime objects</em>. This can easily happen without notice
when reading in a comma-delimited text file. Matplotlib treats lists of strings
as <em>categorical</em> variables
(<a class="reference internal" href="../gallery/lines_bars_and_markers/categorical_variables.html"><span class="doc">Plotting categorical variables</span></a>), and by default
puts one tick per category, and plots them in the order in which they are
supplied.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">matplotlib.pyplot</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nn">plt</span>
<span class="kn">import</span><span class="w"> </span><span class="nn">numpy</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nn">np</span>
<span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</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="n">layout</span><span class="o">=</span><span class="s1">'constrained'</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">6</span><span class="p">,</span> <span class="mi">2</span><span class="p">))</span>
<span class="n">ax</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">'Ticks seem out of order / misplaced'</span><span class="p">)</span>
<span class="n">x</span> <span class="o">=</span> <span class="p">[</span><span class="s1">'5'</span><span class="p">,</span> <span class="s1">'20'</span><span class="p">,</span> <span class="s1">'1'</span><span class="p">,</span> <span class="s1">'9'</span><span class="p">]</span> <span class="c1"># strings</span>
<span class="n">y</span> <span class="o">=</span> <span class="p">[</span><span class="mi">5</span><span class="p">,</span> <span class="mi">20</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">9</span><span class="p">]</span>
<span class="n">ax</span><span class="p">[</span><span class="mi">0</span><span class="p">]</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">'d'</span><span class="p">)</span>
<span class="n">ax</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">tick_params</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="s1">'x'</span><span class="p">,</span> <span class="n">labelcolor</span><span class="o">=</span><span class="s1">'red'</span><span class="p">,</span> <span class="n">labelsize</span><span class="o">=</span><span class="mi">14</span><span class="p">)</span>
<span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">'Many ticks'</span><span class="p">)</span>
<span class="n">x</span> <span class="o">=</span> <span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">xx</span><span class="p">)</span> <span class="k">for</span> <span class="n">xx</span> <span class="ow">in</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">100</span><span class="p">)]</span> <span class="c1"># strings</span>
<span class="n">y</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="mi">100</span><span class="p">)</span>
<span class="n">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">]</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">ax</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">tick_params</span><span class="p">(</span><span class="n">axis</span><span class="o">=</span><span class="s1">'x'</span><span class="p">,</span> <span class="n">labelcolor</span><span class="o">=</span><span class="s1">'red'</span><span class="p">,</span> <span class="n">labelsize</span><span class="o">=</span><span class="mi">14</span><span class="p">)</span>
</pre></div>
</div>
<p>(<a class="reference download internal" download="" href="../_downloads/5a1bd6b33d2fad4b4fde85b7d0324aa9/faq-1.py"><code class="xref download docutils literal notranslate"><span class="pre">Source</span> <span class="pre">code</span></code></a>, <a class="reference download internal" download="" href="../_downloads/156cbc0e2a724bcbf8ea4dfbca668dcd/faq-1.2x.png"><code class="xref download docutils literal notranslate"><span class="pre">2x.png</span></code></a>, <a class="reference download internal" download="" href="../_downloads/e7ff1e5d25c51f435350824e98cb7d73/faq-1.png"><code class="xref download docutils literal notranslate"><span class="pre">png</span></code></a>)</p>
<figure class="align-center">
<a class="reference internal image-reference" href="../_images/users-faq-1.2x.png">
<img alt="" class="plot-directive" src="../_images/users-faq-1.png" srcset="../_images/users-faq-1.png, ../_images/users-faq-1.2x.png 2.00x" />
</a>
</figure>
<p>The solution is to convert the list of strings to numbers or
datetime objects (often <code class="docutils literal notranslate"><span class="pre">np.asarray(numeric_strings,</span> <span class="pre">dtype='float')</span></code> or
<code class="docutils literal notranslate"><span class="pre">np.asarray(datetime_strings,</span> <span class="pre">dtype='datetime64[s]')</span></code>).</p>
<p>For more information see <a class="reference internal" href="../gallery/ticks/ticks_too_many.html"><span class="doc">Fixing too many ticks</span></a>.</p>
</section>
<section id="determine-the-extent-of-artists-in-the-figure">
<span id="howto-determine-artist-extent"></span><h2>Determine the extent of Artists in the Figure<a class="headerlink" href="#determine-the-extent-of-artists-in-the-figure" title="Link to this heading">#</a></h2>
<p>Sometimes we want to know the extent of an Artist. Matplotlib <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> objects
have a method <a class="reference internal" href="../api/_as_gen/matplotlib.artist.Artist.get_window_extent.html#matplotlib.artist.Artist.get_window_extent" title="matplotlib.artist.Artist.get_window_extent"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Artist.get_window_extent</span></code></a> that will usually return the extent of
the artist in pixels. However, some artists, in particular text, must be
rendered at least once before their extent is known. Matplotlib supplies
<a class="reference internal" href="../api/_as_gen/matplotlib.figure.Figure.draw_without_rendering.html#matplotlib.figure.Figure.draw_without_rendering" title="matplotlib.figure.Figure.draw_without_rendering"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Figure.draw_without_rendering</span></code></a>, which should be called before calling
<code class="docutils literal notranslate"><span class="pre">get_window_extent</span></code>.</p>
</section>
<section id="check-whether-a-figure-is-empty">
<span id="howto-figure-empty"></span><h2>Check whether a figure is empty<a class="headerlink" href="#check-whether-a-figure-is-empty" title="Link to this heading">#</a></h2>
<p>Empty can actually mean different things. Does the figure contain any artists?
Does a figure with an empty <a class="reference internal" href="../api/_as_gen/matplotlib.axes.Axes.html#matplotlib.axes.Axes" title="matplotlib.axes.Axes"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Axes</span></code></a> still count as empty? Is the figure
empty if it was rendered pure white (there may be artists present, but they
could be outside the drawing area or transparent)?</p>
<p>For the purpose here, we define empty as: "The figure does not contain any
artists except it's background patch." The exception for the background is
necessary, because by default every figure contains a <a class="reference internal" href="../api/_as_gen/matplotlib.patches.Rectangle.html#matplotlib.patches.Rectangle" title="matplotlib.patches.Rectangle"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Rectangle</span></code></a> as it's
background patch. This definition could be checked via:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">is_empty</span><span class="p">(</span><span class="n">figure</span><span class="p">):</span>
<span class="w"> </span><span class="sd">"""</span>
<span class="sd"> Return whether the figure contains no Artists (other than the default</span>
<span class="sd"> background patch).</span>
<span class="sd"> """</span>
<span class="n">contained_artists</span> <span class="o">=</span> <span class="n">figure</span><span class="o">.</span><span class="n">get_children</span><span class="p">()</span>
<span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="n">contained_artists</span><span class="p">)</span> <span class="o"><=</span> <span class="mi">1</span>
</pre></div>
</div>
<p>We've decided not to include this as a figure method because this is only one
way of defining empty, and checking the above is only rarely necessary.
Usually the user or program handling the figure know if they have added
something to the figure.</p>
<p>The only reliable way to check whether a figure would render empty is to
actually perform such a rendering and inspect the result.</p>
</section>
<section id="find-all-objects-in-a-figure-of-a-certain-type">
<span id="howto-findobj"></span><h2>Find all objects in a figure of a certain type<a class="headerlink" href="#find-all-objects-in-a-figure-of-a-certain-type" title="Link to this heading">#</a></h2>
<p>Every Matplotlib artist (see <a class="reference internal" href="../tutorials/artists.html#artists-tutorial"><span class="std std-ref">Artist tutorial</span></a>) has a method
called <a class="reference internal" href="../api/_as_gen/matplotlib.artist.Artist.findobj.html#matplotlib.artist.Artist.findobj" title="matplotlib.artist.Artist.findobj"><code class="xref py py-meth docutils literal notranslate"><span class="pre">findobj()</span></code></a> that can be used to
recursively search the artist for any artists it may contain that meet
some criteria (e.g., match all <a class="reference internal" href="../api/_as_gen/matplotlib.lines.Line2D.html#matplotlib.lines.Line2D" title="matplotlib.lines.Line2D"><code class="xref py py-class docutils literal notranslate"><span class="pre">Line2D</span></code></a>
instances or match some arbitrary filter function). For example, the
following snippet finds every object in the figure which has a
<code class="docutils literal notranslate"><span class="pre">set_color</span></code> property and makes the object blue:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">myfunc</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
<span class="k">return</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="s1">'set_color'</span><span class="p">)</span>
<span class="k">for</span> <span class="n">o</span> <span class="ow">in</span> <span class="n">fig</span><span class="o">.</span><span class="n">findobj</span><span class="p">(</span><span class="n">myfunc</span><span class="p">):</span>
<span class="n">o</span><span class="o">.</span><span class="n">set_color</span><span class="p">(</span><span class="s1">'blue'</span><span class="p">)</span>
</pre></div>
</div>
<p>You can also filter on class instances:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">matplotlib.text</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nn">text</span>
<span class="k">for</span> <span class="n">o</span> <span class="ow">in</span> <span class="n">fig</span><span class="o">.</span><span class="n">findobj</span><span class="p">(</span><span class="n">text</span><span class="o">.</span><span class="n">Text</span><span class="p">):</span>
<span class="n">o</span><span class="o">.</span><span class="n">set_fontstyle</span><span class="p">(</span><span class="s1">'italic'</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="prevent-ticklabels-from-having-an-offset">
<span id="howto-suppress-offset"></span><h2>Prevent ticklabels from having an offset<a class="headerlink" href="#prevent-ticklabels-from-having-an-offset" title="Link to this heading">#</a></h2>
<p>The default formatter will use an offset to reduce
the length of the ticklabels. To turn this feature
off on a per-axis basis:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ax</span><span class="o">.</span><span class="n">xaxis</span><span class="o">.</span><span class="n">get_major_formatter</span><span class="p">()</span><span class="o">.</span><span class="n">set_useOffset</span><span class="p">(</span><span class="kc">False</span><span class="p">)</span>
</pre></div>
</div>
<p>set <code class="docutils literal notranslate"><a class="reference internal" href="explain/customizing.html?highlight=axes.formatter.useoffset#matplotlibrc-sample"><span class="std std-ref"><span class="pre">rcParams["axes.formatter.useoffset"]</span></span></a></code> (default: <code class="docutils literal notranslate"><span class="pre">True</span></code>), or use a different
formatter. See <a class="reference internal" href="../api/ticker_api.html#module-matplotlib.ticker" title="matplotlib.ticker"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ticker</span></code></a> for details.</p>
</section>
<section id="save-transparent-figures">
<span id="howto-transparent"></span><h2>Save transparent figures<a class="headerlink" href="#save-transparent-figures" title="Link to this heading">#</a></h2>
<p>The <a class="reference internal" href="../api/_as_gen/matplotlib.pyplot.savefig.html#matplotlib.pyplot.savefig" title="matplotlib.pyplot.savefig"><code class="xref py py-meth docutils literal notranslate"><span class="pre">savefig()</span></code></a> command has a keyword argument
<em>transparent</em> which, if 'True', will make the figure and axes
backgrounds transparent when saving, but will not affect the displayed
image on the screen.</p>
<p>If you need finer grained control, e.g., you do not want full transparency
or you want to affect the screen displayed version as well, you can set
the alpha properties directly. The figure has a
<a class="reference internal" href="../api/_as_gen/matplotlib.patches.Rectangle.html#matplotlib.patches.Rectangle" title="matplotlib.patches.Rectangle"><code class="xref py py-class docutils literal notranslate"><span class="pre">Rectangle</span></code></a> instance called <em>patch</em>
and the axes has a Rectangle instance called <em>patch</em>. You can set
any property on them directly (<em>facecolor</em>, <em>edgecolor</em>, <em>linewidth</em>,
<em>linestyle</em>, <em>alpha</em>). e.g.:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">()</span>
<span class="n">fig</span><span class="o">.</span><span class="n">patch</span><span class="o">.</span><span class="n">set_alpha</span><span class="p">(</span><span class="mf">0.5</span><span class="p">)</span>
<span class="n">ax</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_subplot</span><span class="p">(</span><span class="mi">111</span><span class="p">)</span>
<span class="n">ax</span><span class="o">.</span><span class="n">patch</span><span class="o">.</span><span class="n">set_alpha</span><span class="p">(</span><span class="mf">0.5</span><span class="p">)</span>
</pre></div>
</div>
<p>If you need <em>all</em> the figure elements to be transparent, there is
currently no global alpha setting, but you can set the alpha channel
on individual elements, e.g.:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ax</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">alpha</span><span class="o">=</span><span class="mf">0.5</span><span class="p">)</span>
<span class="n">ax</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">'volts'</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mf">0.5</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="save-multiple-plots-to-one-pdf-file">
<span id="howto-multipage"></span><h2>Save multiple plots to one pdf file<a class="headerlink" href="#save-multiple-plots-to-one-pdf-file" title="Link to this heading">#</a></h2>
<p>Many image file formats can only have one image per file, but some formats
support multi-page files. Currently, Matplotlib only provides multi-page
output to pdf files, using either the pdf or pgf backends, via the
<a class="reference internal" href="../api/backend_pdf_api.html#matplotlib.backends.backend_pdf.PdfPages" title="matplotlib.backends.backend_pdf.PdfPages"><code class="xref py py-obj docutils literal notranslate"><span class="pre">backend_pdf.PdfPages</span></code></a> and <a class="reference internal" href="../api/backend_pgf_api.html#matplotlib.backends.backend_pgf.PdfPages" title="matplotlib.backends.backend_pgf.PdfPages"><code class="xref py py-obj docutils literal notranslate"><span class="pre">backend_pgf.PdfPages</span></code></a> classes.</p>
</section>
<section id="make-room-for-tick-labels">
<span id="howto-auto-adjust"></span><h2>Make room for tick labels<a class="headerlink" href="#make-room-for-tick-labels" title="Link to this heading">#</a></h2>
<p>By default, Matplotlib uses fixed percentage margins around subplots. This can
lead to labels overlapping or being cut off at the figure boundary. There are
multiple ways to fix this:</p>
<ul class="simple">
<li><p>Manually adapt the subplot parameters using <a class="reference internal" href="../api/_as_gen/matplotlib.figure.Figure.subplots_adjust.html#matplotlib.figure.Figure.subplots_adjust" title="matplotlib.figure.Figure.subplots_adjust"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Figure.subplots_adjust</span></code></a> /
<a class="reference internal" href="../api/_as_gen/matplotlib.pyplot.subplots_adjust.html#matplotlib.pyplot.subplots_adjust" title="matplotlib.pyplot.subplots_adjust"><code class="xref py py-obj docutils literal notranslate"><span class="pre">pyplot.subplots_adjust</span></code></a>.</p></li>
<li><p>Use one of the automatic layout mechanisms:</p>
<ul>
<li><p>constrained layout (<a class="reference internal" href="explain/axes/constrainedlayout_guide.html#constrainedlayout-guide"><span class="std std-ref">Constrained layout guide</span></a>)</p></li>
<li><p>tight layout (<a class="reference internal" href="explain/axes/tight_layout_guide.html#tight-layout-guide"><span class="std std-ref">Tight layout guide</span></a>)</p></li>
</ul>
</li>
<li><p>Calculate good values from the size of the plot elements yourself
(<a class="reference internal" href="../gallery/subplots_axes_and_figures/auto_subplots_adjust.html"><span class="doc">Programmatically control subplot adjustment</span></a>)</p></li>
</ul>
</section>
<section id="align-my-ylabels-across-multiple-subplots">
<span id="howto-align-label"></span><h2>Align my ylabels across multiple subplots<a class="headerlink" href="#align-my-ylabels-across-multiple-subplots" title="Link to this heading">#</a></h2>
<p>If you have multiple subplots over one another, and the y data have
different scales, you can often get ylabels that do not align
vertically across the multiple subplots, which can be unattractive.
By default, Matplotlib positions the x location of the ylabel so that
it does not overlap any of the y ticks. You can override this default
behavior by specifying the coordinates of the label. To learn how, see
<a class="reference internal" href="../gallery/subplots_axes_and_figures/align_labels_demo.html"><span class="doc">Align labels and titles</span></a></p>
</section>
<section id="control-the-draw-order-of-plot-elements">
<span id="howto-set-zorder"></span><h2>Control the draw order of plot elements<a class="headerlink" href="#control-the-draw-order-of-plot-elements" title="Link to this heading">#</a></h2>
<p>The draw order of plot elements, and thus which elements will be on top, is
determined by the <a class="reference internal" href="../api/_as_gen/matplotlib.artist.Artist.set_zorder.html#matplotlib.artist.Artist.set_zorder" title="matplotlib.artist.Artist.set_zorder"><code class="xref py py-obj docutils literal notranslate"><span class="pre">set_zorder</span></code></a> property.
See <a class="reference internal" href="../gallery/misc/zorder_demo.html"><span class="doc">Zorder Demo</span></a> for a detailed description.</p>
</section>
<section id="make-the-aspect-ratio-for-plots-equal">
<span id="howto-axis-equal"></span><h2>Make the aspect ratio for plots equal<a class="headerlink" href="#make-the-aspect-ratio-for-plots-equal" title="Link to this heading">#</a></h2>
<p>The Axes property <a class="reference internal" href="../api/_as_gen/matplotlib.axes.Axes.set_aspect.html#matplotlib.axes.Axes.set_aspect" title="matplotlib.axes.Axes.set_aspect"><code class="xref py py-meth docutils literal notranslate"><span class="pre">set_aspect()</span></code></a> controls the
aspect ratio of the axes. You can set it to be 'auto', 'equal', or
some ratio which controls the ratio:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">ax</span> <span class="o">=</span> <span class="n">fig</span><span class="o">.</span><span class="n">add_subplot</span><span class="p">(</span><span class="mi">111</span><span class="p">,</span> <span class="n">aspect</span><span class="o">=</span><span class="s1">'equal'</span><span class="p">)</span>
</pre></div>
</div>
<p>See <a class="reference internal" href="../gallery/subplots_axes_and_figures/axis_equal_demo.html"><span class="doc">Equal axis aspect ratio</span></a> for a
complete example.</p>
</section>
<section id="draw-multiple-y-axis-scales">
<span id="howto-twoscale"></span><h2>Draw multiple y-axis scales<a class="headerlink" href="#draw-multiple-y-axis-scales" title="Link to this heading">#</a></h2>
<p>A frequent request is to have two scales for the left and right
y-axis, which is possible using <a class="reference internal" href="../api/_as_gen/matplotlib.pyplot.twinx.html#matplotlib.pyplot.twinx" title="matplotlib.pyplot.twinx"><code class="xref py py-func docutils literal notranslate"><span class="pre">twinx()</span></code></a> (more
than two scales are not currently supported, though it is on the wish
list). This works pretty well, though there are some quirks when you
are trying to interactively pan and zoom, because both scales do not get
the signals.</p>
<p>The approach uses <a class="reference internal" href="../api/_as_gen/matplotlib.pyplot.twinx.html#matplotlib.pyplot.twinx" title="matplotlib.pyplot.twinx"><code class="xref py py-func docutils literal notranslate"><span class="pre">twinx()</span></code></a> (and its sister
<a class="reference internal" href="../api/_as_gen/matplotlib.pyplot.twiny.html#matplotlib.pyplot.twiny" title="matplotlib.pyplot.twiny"><code class="xref py py-func docutils literal notranslate"><span class="pre">twiny()</span></code></a>) to use <em>2 different axes</em>,
turning the axes rectangular frame off on the 2nd axes to keep it from
obscuring the first, and manually setting the tick locs and labels as
desired. You can use separate <code class="docutils literal notranslate"><span class="pre">matplotlib.ticker</span></code> formatters and
locators as desired because the two axes are independent.</p>
<p>(<a class="reference download internal" download="" href="../_downloads/44b5432bcc59ab8b9b8a6545b0ae281f/faq-2.py"><code class="xref download docutils literal notranslate"><span class="pre">Source</span> <span class="pre">code</span></code></a>, <a class="reference download internal" download="" href="../_downloads/5b35eae77b9d97177298700c52e5d640/faq-2.2x.png"><code class="xref download docutils literal notranslate"><span class="pre">2x.png</span></code></a>, <a class="reference download internal" download="" href="../_downloads/f55704b6a74aaf141da69633eba9787e/faq-2.png"><code class="xref download docutils literal notranslate"><span class="pre">png</span></code></a>)</p>
<figure class="align-center">
<a class="reference internal image-reference" href="../_images/users-faq-2.2x.png">
<img alt="" class="plot-directive" src="../_images/users-faq-2.png" srcset="../_images/users-faq-2.png, ../_images/users-faq-2.2x.png 2.00x" />
</a>
</figure>
<p>See <a class="reference internal" href="../gallery/subplots_axes_and_figures/two_scales.html"><span class="doc">Plots with different scales</span></a> for a
complete example.</p>
</section>
<section id="generate-images-without-having-a-window-appear">
<span id="howto-batch"></span><h2>Generate images without having a window appear<a class="headerlink" href="#generate-images-without-having-a-window-appear" title="Link to this heading">#</a></h2>
<p>Simply do not call <a class="reference internal" href="../api/_as_gen/matplotlib.pyplot.show.html#matplotlib.pyplot.show" title="matplotlib.pyplot.show"><code class="xref py py-obj docutils literal notranslate"><span class="pre">show</span></code></a>, and directly save the figure to
the desired format:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span><span class="w"> </span><span class="nn">matplotlib.pyplot</span><span class="w"> </span><span class="k">as</span><span class="w"> </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="n">plt</span><span class="o">.</span><span class="n">savefig</span><span class="p">(</span><span class="s1">'myfig.png'</span><span class="p">)</span>
<span class="n">plt</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="../gallery/user_interfaces/web_application_server_sgskip.html"><span class="doc">Embed in a web application server (Flask)</span></a> for
information about running matplotlib inside of a web application.</p>
</div>
</section>
<section id="work-with-threads">
<span id="how-to-threads"></span><h2>Work with threads<a class="headerlink" href="#work-with-threads" title="Link to this heading">#</a></h2>
<p>Matplotlib is not thread-safe: in fact, there are known race conditions
that affect certain artists. Hence, if you work with threads, it is your
responsibility to set up the proper locks to serialize access to Matplotlib
artists.</p>
<p>You may be able to work on separate figures from separate threads. However,
you must in that case use a <em>non-interactive backend</em> (typically Agg), because
most GUI backends <em>require</em> being run from the main thread as well.</p>
</section>
<section id="get-help">
<span id="reporting-problems"></span><span id="id1"></span><h2>Get help<a class="headerlink" href="#get-help" title="Link to this heading">#</a></h2>
<p>There are a number of good resources for getting help with Matplotlib.
There is a good chance your question has already been asked:</p>
<ul class="simple">
<li><p>The <a class="reference external" href="https://discourse.matplotlib.org/c/community/matplotlib-users/6">mailing list archive</a>.</p></li>
<li><p><a class="reference external" href="https://github.com/matplotlib/matplotlib/issues">GitHub issues</a>.</p></li>
<li><p>Stackoverflow questions tagged <a class="reference external" href="https://stackoverflow.com/questions/tagged/matplotlib">matplotlib</a>.</p></li>
</ul>
<p>If you are unable to find an answer to your question through search, please
provide the following information in your e-mail to the <a class="reference external" href="https://mail.python.org/mailman/listinfo/matplotlib-users">mailing list</a>:</p>
<ul>
<li><p>Your operating system (Linux/Unix users: post the output of <code class="docutils literal notranslate"><span class="pre">uname</span> <span class="pre">-a</span></code>).</p></li>
<li><p>Matplotlib version:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="o">-</span><span class="n">c</span> <span class="s2">"import matplotlib; print(matplotlib.__version__)"</span>
</pre></div>
</div>
</li>
<li><p>Where you obtained Matplotlib (e.g., your Linux distribution's packages,
GitHub, PyPI, or <a class="reference external" href="https://www.anaconda.com/">Anaconda</a>).</p></li>
<li><p>Any customizations to your <code class="docutils literal notranslate"><span class="pre">matplotlibrc</span></code> file (see
<a class="reference internal" href="explain/customizing.html#customizing"><span class="std std-ref">Customizing Matplotlib with style sheets and rcParams</span></a>).</p></li>
<li><p>If the problem is reproducible, please try to provide a <em>minimal</em>, standalone
Python script that demonstrates the problem. This is <em>the</em> critical step.
If you can't post a piece of code that we can run and reproduce your error,
the chances of getting help are significantly diminished. Very often, the
mere act of trying to minimize your code to the smallest bit that produces
the error will help you find a bug in <em>your</em> code that is causing the
problem.</p></li>
<li><p>Matplotlib provides debugging information through the <a class="reference external" href="https://docs.python.org/3/library/logging.html#module-logging" title="(in Python v3.13)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">logging</span></code></a> library, and
a helper function to set the logging level: one can call</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">plt</span><span class="o">.</span><span class="n">set_loglevel</span><span class="p">(</span><span class="s2">"info"</span><span class="p">)</span> <span class="c1"># or "debug" for more info</span>
</pre></div>
</div>
<p>to obtain this debugging information.</p>
<p>Standard functions from the <a class="reference external" href="https://docs.python.org/3/library/logging.html#module-logging" title="(in Python v3.13)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">logging</span></code></a> module are also applicable; e.g. one
could call <code class="docutils literal notranslate"><span class="pre">logging.basicConfig(level="DEBUG")</span></code> even before importing
Matplotlib (this is in particular necessary to get the logging info emitted
during Matplotlib's import), or attach a custom handler to the "matplotlib"
logger. This may be useful if you use a custom logging configuration.</p>
</li>
</ul>
<p>If you compiled Matplotlib yourself, please also provide:</p>
<ul>
<li><p>your compiler version -- e.g., <code class="docutils literal notranslate"><span class="pre">gcc</span> <span class="pre">--version</span></code>.</p></li>
<li><p>the output of:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">pip</span> <span class="n">install</span> <span class="o">--</span><span class="n">verbose</span>
</pre></div>
</div>
<p>The beginning of the build output contains lots of details about your
platform that are useful for the Matplotlib developers to diagnose your
problem.</p>
</li>
</ul>
<p>If you compiled an older version of Matplotlib using the pre-Meson build system, instead
provide:</p>
<ul>
<li><p>any changes you have made to <code class="docutils literal notranslate"><span class="pre">setup.py</span></code>/<code class="docutils literal notranslate"><span class="pre">setupext.py</span></code>,</p></li>
<li><p>the output of:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">rm</span> <span class="o">-</span><span class="n">rf</span> <span class="n">build</span>
<span class="n">python</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">build</span>
</pre></div>
</div>
</li>
</ul>
<p>Including this information in your first e-mail to the mailing list
will save a lot of time.</p>
<p>You will likely get a faster response writing to the mailing list than
filing a bug in the bug tracker. Most developers check the bug
tracker only periodically. If your problem has been determined to be
a bug and cannot be quickly solved, you may be asked to file a bug in
the tracker so the issue doesn't get lost.</p>
</section>
</section>
</article>
</div>
<div class="bd-sidebar-secondary bd-toc"><div class="sidebar-secondary-items sidebar-secondary__inner">
<div class="sidebar-secondary-item">
<div
id="pst-page-navigation-heading-2"
class="page-toc tocsection onthispage">
<i class="fa-solid fa-list"></i> On this page
</div>
<nav class="bd-toc-nav page-toc" aria-labelledby="pst-page-navigation-heading-2">
<ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#i-don-t-see-a-figure-window">I don't see a figure window</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#why-do-i-have-so-many-ticks-and-or-why-are-they-out-of-order">Why do I have so many ticks, and/or why are they out of order?</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#determine-the-extent-of-artists-in-the-figure">Determine the extent of Artists in the Figure</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#check-whether-a-figure-is-empty">Check whether a figure is empty</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#find-all-objects-in-a-figure-of-a-certain-type">Find all objects in a figure of a certain type</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#prevent-ticklabels-from-having-an-offset">Prevent ticklabels from having an offset</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#save-transparent-figures">Save transparent figures</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#save-multiple-plots-to-one-pdf-file">Save multiple plots to one pdf file</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#make-room-for-tick-labels">Make room for tick labels</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#align-my-ylabels-across-multiple-subplots">Align my ylabels across multiple subplots</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#control-the-draw-order-of-plot-elements">Control the draw order of plot elements</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#make-the-aspect-ratio-for-plots-equal">Make the aspect ratio for plots equal</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#draw-multiple-y-axis-scales">Draw multiple y-axis scales</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#generate-images-without-having-a-window-appear">Generate images without having a window appear</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#work-with-threads">Work with threads</a></li>
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#get-help">Get help</a></li>
</ul>
</nav></div>
</div></div>
</div>
<footer class="bd-footer-content">
</footer>
</main>
</div>
</div>
<!-- Scripts loaded after <body> so the DOM is not blocked -->
<script src="../_static/scripts/bootstrap.js?digest=dfe6caa3a7d634c4db9b"></script>
<script src="../_static/scripts/pydata-sphinx-theme.js?digest=dfe6caa3a7d634c4db9b"></script>
<footer class="bd-footer">
<div class="bd-footer__inner bd-page-width">
<div class="footer-items__start">
<div class="footer-item">
<p class="copyright">
© Copyright 2002–2012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom and the Matplotlib development team; 2012–2025 The Matplotlib development team.
<br/>
</p>
</div>
<div class="footer-item">
<p class="sphinx-version">
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.
<br/>
</p>
</div>
<div class="footer-item">
<p class="sphinx-version">
Built from v3.10.1-711-g492a478bfe.
<br/>
</p>
</div>
</div>
<div class="footer-items__end">
<div class="footer-item">
<p class="theme-version">