-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathcolormaps.html
More file actions
1002 lines (895 loc) · 108 KB
/
colormaps.html
File metadata and controls
1002 lines (895 loc) · 108 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 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>Choosing Colormaps in Matplotlib — Matplotlib 3.5.2 documentation</title>
<!-- Loaded before other Sphinx assets -->
<link href="../../_static/styles/theme.css?digest=1999514e3f237ded88cf" rel="stylesheet">
<link href="../../_static/styles/pydata-sphinx-theme.css?digest=1999514e3f237ded88cf" rel="stylesheet">
<link rel="stylesheet"
href="../../_static/vendor/fontawesome/5.13.0/css/all.min.css">
<link rel="preload" as="font" type="font/woff2" crossorigin
href="../../_static/vendor/fontawesome/5.13.0/webfonts/fa-solid-900.woff2">
<link rel="preload" as="font" type="font/woff2" crossorigin
href="../../_static/vendor/fontawesome/5.13.0/webfonts/fa-brands-400.woff2">
<link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="../../_static/css/style.css" />
<link rel="stylesheet" type="text/css" href="../../_static/graphviz.css" />
<link rel="stylesheet" type="text/css" href="../../_static/plot_directive.css" />
<link rel="stylesheet" type="text/css" href="../../_static/copybutton.css" />
<link rel="stylesheet" type="text/css" href="../../_static/sg_gallery.css" />
<link rel="stylesheet" type="text/css" href="../../_static/sg_gallery-binder.css" />
<link rel="stylesheet" type="text/css" href="../../_static/sg_gallery-dataframe.css" />
<link rel="stylesheet" type="text/css" href="../../_static/sg_gallery-rendered-html.css" />
<link rel="stylesheet" type="text/css" href="../../_static/panels-main.c949a650a448cc0ae9fd3441c0e17fb0.css" />
<link rel="stylesheet" type="text/css" href="../../_static/panels-variables.06eb56fa6e07937060861dad626602ad.css" />
<link rel="stylesheet" type="text/css" href="../../_static/mpl.css?v3.5.2-3-g2e7af710d5" />
<!-- Pre-loaded scripts that we'll load fully later -->
<link rel="preload" as="script" href="../../_static/scripts/pydata-sphinx-theme.js?digest=1999514e3f237ded88cf">
<script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script>
<script src="../../_static/underscore.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/clipboard.min.js"></script>
<script src="../../_static/copybutton.js"></script>
<script async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<link rel="canonical" href="https://matplotlib.org/stable/tutorials/colors/colormaps.html" />
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Matplotlib 3.5.2 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="Complex and semantic figure composition" href="../provisional/mosaic.html" />
<link rel="prev" title="Colormap Normalization" href="colormapnorms.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="None">
<script data-domain="matplotlib.org" defer="defer" src="https://views.scientific-python.org/js/script.js"></script>
</head>
<body data-spy="scroll" data-target="#bd-toc-nav" data-offset="60">
<div class="container-fluid" id="banner"></div>
<nav class="navbar navbar-light navbar-expand-lg bg-light fixed-top bd-navbar" id="navbar-main"><div class="container-xl">
<div id="navbar-start">
<a class="navbar-brand" href="../../index.html">
<img src="../../_static/logo2.svg" class="logo" alt="logo">
</a>
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-collapsible" aria-controls="navbar-collapsible" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div id="navbar-collapsible" class="col-lg-9 collapse navbar-collapse">
<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">
<ul id="navbar-icon-links" class="navbar-nav" aria-label="Icon Links">
<li class="nav-item">
<a class="nav-link" href="https://gitter.im/matplotlib/matplotlib" rel="noopener" target="_blank" title="gitter">
<span><i class="fab fa-gitter"></i></span>
<label class="sr-only">gitter</label>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://discourse.matplotlib.org" rel="noopener" target="_blank" title="discourse">
<span><i class="fab fa-discourse"></i></span>
<label class="sr-only">discourse</label>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/matplotlib/matplotlib" rel="noopener" target="_blank" title="GitHub">
<span><i class="fab fa-github-square"></i></span>
<label class="sr-only">GitHub</label>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://twitter.com/matplotlib/" rel="noopener" target="_blank" title="twitter">
<span><i class="fab fa-twitter-square"></i></span>
<label class="sr-only">twitter</label>
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</nav>
<div class="container-xl">
<div class="row">
<!-- Only show if we have sidebars configured, else just a small margin -->
<div class="col-12 col-md-3 bd-sidebar">
<div class="sidebar-start-items"><form class="bd-search d-flex align-items-center" action="../../search.html" method="get">
<i class="icon fas fa-search"></i>
<input type="search" class="form-control" name="q" id="search-input" placeholder="Search the docs ..." aria-label="Search the docs ..." autocomplete="off" >
</form><nav class="bd-links" id="bd-docs-nav" aria-label="Main navigation">
<div class="bd-toc-item active">
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../introductory/usage.html">
Basic Usage
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../introductory/pyplot.html">
Pyplot tutorial
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../introductory/images.html">
Image tutorial
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../introductory/lifecycle.html">
The Lifecycle of a Plot
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../introductory/customizing.html">
Customizing Matplotlib with style sheets and rcParams
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../intermediate/artists.html">
Artist tutorial
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../intermediate/legend_guide.html">
Legend guide
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../intermediate/color_cycle.html">
Styling with cycler
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../intermediate/constrainedlayout_guide.html">
Constrained Layout Guide
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../intermediate/tight_layout_guide.html">
Tight Layout guide
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../intermediate/arranging_axes.html">
Arranging multiple Axes in a Figure
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../intermediate/autoscale.html">
Autoscaling
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<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>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../advanced/blitting.html">
Faster rendering by using blitting
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../advanced/path_tutorial.html">
Path Tutorial
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../advanced/patheffects_guide.html">
Path effects guide
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../advanced/transforms_tutorial.html">
Transformations Tutorial
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="colors.html">
Specifying Colors
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="colorbar_only.html">
Customized Colorbars Tutorial
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="colormap-manipulation.html">
Creating Colormaps in Matplotlib
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="colormapnorms.html">
Colormap Normalization
</a>
</li>
</ul>
<ul class="current nav bd-sidenav">
<li class="toctree-l1 current active">
<a class="current reference internal" href="#">
Choosing Colormaps in Matplotlib
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../provisional/mosaic.html">
Complex and semantic figure composition
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../text/text_intro.html">
Text in Matplotlib Plots
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../text/text_props.html">
Text properties and layout
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../text/annotations.html">
Annotations
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../text/mathtext.html">
Writing mathematical expressions
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../text/pgf.html">
Typesetting with XeLaTeX/LuaLaTeX via the
<code class="docutils literal notranslate">
<span class="pre">
pgf
</span>
</code>
backend
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../text/usetex.html">
Text rendering with LaTeX
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../toolkits/axes_grid.html">
Overview of
<code class="xref py py-mod docutils literal notranslate">
<span class="pre">
mpl_toolkits.axes_grid1
</span>
</code>
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../toolkits/axisartist.html">
Overview of axisartist toolkit
</a>
</li>
</ul>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../toolkits/mplot3d.html">
The mplot3d Toolkit
</a>
</li>
</ul>
</div>
</nav>
</div>
<div class="sidebar-end-items">
</div>
</div>
<div class="d-none d-xl-block col-xl-2 bd-toc">
<div class="toc-item">
<div class="tocsection onthispage mt-5 pt-1 pb-3">
<i class="fas fa-list"></i> On this page
</div>
<nav id="bd-toc-nav">
<ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#overview">
Overview
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#classes-of-colormaps">
Classes of colormaps
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#sequential">
Sequential
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#sequential2">
Sequential2
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#diverging">
Diverging
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#cyclic">
Cyclic
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#qualitative">
Qualitative
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#miscellaneous">
Miscellaneous
</a>
</li>
</ul>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#lightness-of-matplotlib-colormaps">
Lightness of Matplotlib colormaps
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#grayscale-conversion">
Grayscale conversion
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#color-vision-deficiencies">
Color vision deficiencies
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#references">
References
</a>
</li>
</ul>
</nav>
</div>
<div class="toc-item">
</div>
</div>
<main class="col-12 col-md-9 col-xl-7 py-md-5 pl-md-5 pr-md-4 bd-content" role="main">
<div>
<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-colors-colormaps-py"><span class="std std-ref">here</span></a>
to download the full example code</p>
</div>
<section class="sphx-glr-example-title" id="choosing-colormaps-in-matplotlib">
<span id="sphx-glr-tutorials-colors-colormaps-py"></span><h1>Choosing Colormaps in Matplotlib<a class="headerlink" href="#choosing-colormaps-in-matplotlib" title="Permalink to this headline">#</a></h1>
<p>Matplotlib has a number of built-in colormaps accessible via
<a class="reference internal" href="../../api/cm_api.html#matplotlib.cm.get_cmap" title="matplotlib.cm.get_cmap"><code class="xref py py-obj docutils literal notranslate"><span class="pre">matplotlib.cm.get_cmap</span></code></a>. There are also external libraries that
have many extra colormaps, which can be viewed in the
<a class="reference external" href="https://matplotlib.org/mpl-third-party/#colormaps-and-styles">Third-party colormaps</a> section of the Matplotlib documentation.
Here we briefly discuss how to choose between the many options. For
help on creating your own colormaps, see
<a class="reference internal" href="colormap-manipulation.html"><span class="doc">Creating Colormaps in Matplotlib</span></a>.</p>
<section id="overview">
<h2>Overview<a class="headerlink" href="#overview" title="Permalink to this headline">#</a></h2>
<p>The idea behind choosing a good colormap is to find a good representation in 3D
colorspace for your data set. The best colormap for any given data set depends
on many things including:</p>
<ul class="simple">
<li><p>Whether representing form or metric data (<a class="reference internal" href="#ware" id="id1"><span>[Ware]</span></a>)</p></li>
<li><p>Your knowledge of the data set (<em>e.g.</em>, is there a critical value
from which the other values deviate?)</p></li>
<li><p>If there is an intuitive color scheme for the parameter you are plotting</p></li>
<li><p>If there is a standard in the field the audience may be expecting</p></li>
</ul>
<p>For many applications, a perceptually uniform colormap is the best choice;
i.e. a colormap in which equal steps in data are perceived as equal
steps in the color space. Researchers have found that the human brain
perceives changes in the lightness parameter as changes in the data
much better than, for example, changes in hue. Therefore, colormaps
which have monotonically increasing lightness through the colormap
will be better interpreted by the viewer. Wonderful examples of
perceptually uniform colormaps can be found in the
<a class="reference external" href="https://matplotlib.org/mpl-third-party/#colormaps-and-styles">Third-party colormaps</a> section as well.</p>
<p>Color can be represented in 3D space in various ways. One way to represent color
is using CIELAB. In CIELAB, color space is represented by lightness,
<span class="math notranslate nohighlight">\(L^*\)</span>; red-green, <span class="math notranslate nohighlight">\(a^*\)</span>; and yellow-blue, <span class="math notranslate nohighlight">\(b^*\)</span>. The lightness
parameter <span class="math notranslate nohighlight">\(L^*\)</span> can then be used to learn more about how the matplotlib
colormaps will be perceived by viewers.</p>
<p>An excellent starting resource for learning about human perception of colormaps
is from <a class="reference internal" href="#ibm" id="id2"><span>[IBM]</span></a>.</p>
</section>
<section id="classes-of-colormaps">
<span id="color-colormaps-reference"></span><h2>Classes of colormaps<a class="headerlink" href="#classes-of-colormaps" title="Permalink to this headline">#</a></h2>
<p>Colormaps are often split into several categories based on their function (see,
<em>e.g.</em>, <a class="reference internal" href="#moreland" id="id3"><span>[Moreland]</span></a>):</p>
<ol class="arabic simple">
<li><p>Sequential: change in lightness and often saturation of color
incrementally, often using a single hue; should be used for
representing information that has ordering.</p></li>
<li><p>Diverging: change in lightness and possibly saturation of two
different colors that meet in the middle at an unsaturated color;
should be used when the information being plotted has a critical
middle value, such as topography or when the data deviates around
zero.</p></li>
<li><p>Cyclic: change in lightness of two different colors that meet in
the middle and beginning/end at an unsaturated color; should be
used for values that wrap around at the endpoints, such as phase
angle, wind direction, or time of day.</p></li>
<li><p>Qualitative: often are miscellaneous colors; should be used to
represent information which does not have ordering or
relationships.</p></li>
</ol>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">matplotlib</span> <span class="k">as</span> <span class="nn">mpl</span>
<span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="kn">from</span> <span class="nn">matplotlib</span> <span class="kn">import</span> <span class="n">cm</span>
<span class="kn">from</span> <span class="nn">colorspacious</span> <span class="kn">import</span> <span class="n">cspace_converter</span>
</pre></div>
</div>
<p>First, we'll show the range of each colormap. Note that some seem
to change more "quickly" than others.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><a href="https://docs.python.org/3/library/stdtypes.html#dict" title="builtins.dict" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmaps</span></a> <span class="o">=</span> <span class="p">{}</span>
<a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">gradient</span></a> <span class="o">=</span> <a href="https://numpy.org/doc/stable/reference/generated/numpy.linspace.html#numpy.linspace" title="numpy.linspace" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-function"><span class="n">np</span><span class="o">.</span><span class="n">linspace</span></a><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">256</span><span class="p">)</span>
<a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">gradient</span></a> <span class="o">=</span> <a href="https://numpy.org/doc/stable/reference/generated/numpy.vstack.html#numpy.vstack" title="numpy.vstack" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-function"><span class="n">np</span><span class="o">.</span><span class="n">vstack</span></a><span class="p">((</span><a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">gradient</span></a><span class="p">,</span> <a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">gradient</span></a><span class="p">))</span>
<span class="k">def</span> <span class="nf">plot_color_gradients</span><span class="p">(</span><span class="n">category</span><span class="p">,</span> <a href="https://docs.python.org/3/library/stdtypes.html#list" title="builtins.list" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap_list</span></a><span class="p">):</span>
<span class="c1"># Create figure and adjust figure height to number of colormaps</span>
<span class="n">nrows</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><a href="https://docs.python.org/3/library/stdtypes.html#list" title="builtins.list" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap_list</span></a><span class="p">)</span>
<span class="n">figh</span> <span class="o">=</span> <span class="mf">0.35</span> <span class="o">+</span> <span class="mf">0.15</span> <span class="o">+</span> <span class="p">(</span><span class="n">nrows</span> <span class="o">+</span> <span class="p">(</span><span class="n">nrows</span> <span class="o">-</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span> <span class="mf">0.1</span><span class="p">)</span> <span class="o">*</span> <span class="mf">0.22</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> <a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">axs</span></a> <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">nrows</span><span class="o">=</span><span class="n">nrows</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mf">6.4</span><span class="p">,</span> <span class="n">figh</span><span class="p">))</span>
<a href="../../api/figure_api.html#matplotlib.figure.Figure.subplots_adjust" title="matplotlib.figure.Figure.subplots_adjust" class="sphx-glr-backref-module-matplotlib-figure sphx-glr-backref-type-py-method"><span class="n">fig</span><span class="o">.</span><span class="n">subplots_adjust</span></a><span class="p">(</span><span class="n">top</span><span class="o">=</span><span class="mi">1</span> <span class="o">-</span> <span class="mf">0.35</span> <span class="o">/</span> <span class="n">figh</span><span class="p">,</span> <span class="n">bottom</span><span class="o">=</span><span class="mf">0.15</span> <span class="o">/</span> <span class="n">figh</span><span class="p">,</span>
<span class="n">left</span><span class="o">=</span><span class="mf">0.2</span><span class="p">,</span> <span class="n">right</span><span class="o">=</span><span class="mf">0.99</span><span class="p">)</span>
<a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">axs</span></a><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="sa">f</span><span class="s1">'</span><span class="si">{</span><span class="n">category</span><span class="si">}</span><span class="s1"> colormaps'</span><span class="p">,</span> <span class="n">fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">)</span>
<span class="k">for</span> <span class="n">ax</span><span class="p">,</span> <span class="n">name</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">axs</span></a><span class="p">,</span> <a href="https://docs.python.org/3/library/stdtypes.html#list" title="builtins.list" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap_list</span></a><span class="p">):</span>
<a href="../../api/_as_gen/matplotlib.axes.Axes.imshow.html#matplotlib.axes.Axes.imshow" title="matplotlib.axes.Axes.imshow" 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">imshow</span></a><span class="p">(</span><a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">gradient</span></a><span class="p">,</span> <span class="n">aspect</span><span class="o">=</span><span class="s1">'auto'</span><span class="p">,</span> <a href="https://docs.python.org/3/library/stdtypes.html#str" title="builtins.str" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap</span></a><span class="o">=</span><span class="n">plt</span><span class="o">.</span><span class="n">get_cmap</span><span class="p">(</span><span class="n">name</span><span class="p">))</span>
<a href="../../api/_as_gen/matplotlib.axes.Axes.text.html#matplotlib.axes.Axes.text" title="matplotlib.axes.Axes.text" 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">text</span></a><span class="p">(</span><span class="o">-</span><span class="mf">0.01</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">va</span><span class="o">=</span><span class="s1">'center'</span><span class="p">,</span> <span class="n">ha</span><span class="o">=</span><span class="s1">'right'</span><span class="p">,</span> <span class="n">fontsize</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span>
<span class="n">transform</span><span class="o">=</span><a href="../../api/transformations.html#matplotlib.transforms.BboxTransformTo" title="matplotlib.transforms.BboxTransformTo" 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">transAxes</span></a><span class="p">)</span>
<span class="c1"># Turn off *all* ticks & spines, not just the ones with colormaps.</span>
<span class="k">for</span> <span class="n">ax</span> <span class="ow">in</span> <a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">axs</span></a><span class="p">:</span>
<a href="../../api/_as_gen/matplotlib.axes.Axes.set_axis_off.html#matplotlib.axes.Axes.set_axis_off" title="matplotlib.axes.Axes.set_axis_off" 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">set_axis_off</span></a><span class="p">()</span>
<span class="c1"># Save colormap list for later.</span>
<a href="https://docs.python.org/3/library/stdtypes.html#dict" title="builtins.dict" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmaps</span></a><span class="p">[</span><span class="n">category</span><span class="p">]</span> <span class="o">=</span> <a href="https://docs.python.org/3/library/stdtypes.html#list" title="builtins.list" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap_list</span></a>
</pre></div>
</div>
<section id="sequential">
<h3>Sequential<a class="headerlink" href="#sequential" title="Permalink to this headline">#</a></h3>
<p>For the Sequential plots, the lightness value increases monotonically through
the colormaps. This is good. Some of the <span class="math notranslate nohighlight">\(L^*\)</span> values in the colormaps
span from 0 to 100 (binary and the other grayscale), and others start around
<span class="math notranslate nohighlight">\(L^*=20\)</span>. Those that have a smaller range of <span class="math notranslate nohighlight">\(L^*\)</span> will accordingly
have a smaller perceptual range. Note also that the <span class="math notranslate nohighlight">\(L^*\)</span> function varies
amongst the colormaps: some are approximately linear in <span class="math notranslate nohighlight">\(L^*\)</span> and others
are more curved.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">plot_color_gradients</span><span class="p">(</span><span class="s1">'Perceptually Uniform Sequential'</span><span class="p">,</span>
<span class="p">[</span><span class="s1">'viridis'</span><span class="p">,</span> <span class="s1">'plasma'</span><span class="p">,</span> <span class="s1">'inferno'</span><span class="p">,</span> <span class="s1">'magma'</span><span class="p">,</span> <span class="s1">'cividis'</span><span class="p">])</span>
</pre></div>
</div>
<img src="../../_images/sphx_glr_colormaps_001.png" srcset="../../_images/sphx_glr_colormaps_001.png, ../../_images/sphx_glr_colormaps_001_2_0x.png 2.0x" alt="Perceptually Uniform Sequential colormaps" class = "sphx-glr-single-img"/><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">plot_color_gradients</span><span class="p">(</span><span class="s1">'Sequential'</span><span class="p">,</span>
<span class="p">[</span><span class="s1">'Greys'</span><span class="p">,</span> <span class="s1">'Purples'</span><span class="p">,</span> <span class="s1">'Blues'</span><span class="p">,</span> <span class="s1">'Greens'</span><span class="p">,</span> <span class="s1">'Oranges'</span><span class="p">,</span> <span class="s1">'Reds'</span><span class="p">,</span>
<span class="s1">'YlOrBr'</span><span class="p">,</span> <span class="s1">'YlOrRd'</span><span class="p">,</span> <span class="s1">'OrRd'</span><span class="p">,</span> <span class="s1">'PuRd'</span><span class="p">,</span> <span class="s1">'RdPu'</span><span class="p">,</span> <span class="s1">'BuPu'</span><span class="p">,</span>
<span class="s1">'GnBu'</span><span class="p">,</span> <span class="s1">'PuBu'</span><span class="p">,</span> <span class="s1">'YlGnBu'</span><span class="p">,</span> <span class="s1">'PuBuGn'</span><span class="p">,</span> <span class="s1">'BuGn'</span><span class="p">,</span> <span class="s1">'YlGn'</span><span class="p">])</span>
</pre></div>
</div>
<img src="../../_images/sphx_glr_colormaps_002.png" srcset="../../_images/sphx_glr_colormaps_002.png, ../../_images/sphx_glr_colormaps_002_2_0x.png 2.0x" alt="Sequential colormaps" class = "sphx-glr-single-img"/></section>
<section id="sequential2">
<h3>Sequential2<a class="headerlink" href="#sequential2" title="Permalink to this headline">#</a></h3>
<p>Many of the <span class="math notranslate nohighlight">\(L^*\)</span> values from the Sequential2 plots are monotonically
increasing, but some (autumn, cool, spring, and winter) plateau or even go both
up and down in <span class="math notranslate nohighlight">\(L^*\)</span> space. Others (afmhot, copper, gist_heat, and hot)
have kinks in the <span class="math notranslate nohighlight">\(L^*\)</span> functions. Data that is being represented in a
region of the colormap that is at a plateau or kink will lead to a perception of
banding of the data in those values in the colormap (see <a class="reference internal" href="#mycarta-banding" id="id4"><span>[mycarta-banding]</span></a> for
an excellent example of this).</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">plot_color_gradients</span><span class="p">(</span><span class="s1">'Sequential (2)'</span><span class="p">,</span>
<span class="p">[</span><span class="s1">'binary'</span><span class="p">,</span> <span class="s1">'gist_yarg'</span><span class="p">,</span> <span class="s1">'gist_gray'</span><span class="p">,</span> <span class="s1">'gray'</span><span class="p">,</span> <span class="s1">'bone'</span><span class="p">,</span>
<span class="s1">'pink'</span><span class="p">,</span> <span class="s1">'spring'</span><span class="p">,</span> <span class="s1">'summer'</span><span class="p">,</span> <span class="s1">'autumn'</span><span class="p">,</span> <span class="s1">'winter'</span><span class="p">,</span> <span class="s1">'cool'</span><span class="p">,</span>
<span class="s1">'Wistia'</span><span class="p">,</span> <span class="s1">'hot'</span><span class="p">,</span> <span class="s1">'afmhot'</span><span class="p">,</span> <span class="s1">'gist_heat'</span><span class="p">,</span> <span class="s1">'copper'</span><span class="p">])</span>
</pre></div>
</div>
<img src="../../_images/sphx_glr_colormaps_003.png" srcset="../../_images/sphx_glr_colormaps_003.png, ../../_images/sphx_glr_colormaps_003_2_0x.png 2.0x" alt="Sequential (2) colormaps" class = "sphx-glr-single-img"/></section>
<section id="diverging">
<h3>Diverging<a class="headerlink" href="#diverging" title="Permalink to this headline">#</a></h3>
<p>For the Diverging maps, we want to have monotonically increasing <span class="math notranslate nohighlight">\(L^*\)</span>
values up to a maximum, which should be close to <span class="math notranslate nohighlight">\(L^*=100\)</span>, followed by
monotonically decreasing <span class="math notranslate nohighlight">\(L^*\)</span> values. We are looking for approximately
equal minimum <span class="math notranslate nohighlight">\(L^*\)</span> values at opposite ends of the colormap. By these
measures, BrBG and RdBu are good options. coolwarm is a good option, but it
doesn't span a wide range of <span class="math notranslate nohighlight">\(L^*\)</span> values (see grayscale section below).</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">plot_color_gradients</span><span class="p">(</span><span class="s1">'Diverging'</span><span class="p">,</span>
<span class="p">[</span><span class="s1">'PiYG'</span><span class="p">,</span> <span class="s1">'PRGn'</span><span class="p">,</span> <span class="s1">'BrBG'</span><span class="p">,</span> <span class="s1">'PuOr'</span><span class="p">,</span> <span class="s1">'RdGy'</span><span class="p">,</span> <span class="s1">'RdBu'</span><span class="p">,</span> <span class="s1">'RdYlBu'</span><span class="p">,</span>
<span class="s1">'RdYlGn'</span><span class="p">,</span> <span class="s1">'Spectral'</span><span class="p">,</span> <span class="s1">'coolwarm'</span><span class="p">,</span> <span class="s1">'bwr'</span><span class="p">,</span> <span class="s1">'seismic'</span><span class="p">])</span>
</pre></div>
</div>
<img src="../../_images/sphx_glr_colormaps_004.png" srcset="../../_images/sphx_glr_colormaps_004.png, ../../_images/sphx_glr_colormaps_004_2_0x.png 2.0x" alt="Diverging colormaps" class = "sphx-glr-single-img"/></section>
<section id="cyclic">
<h3>Cyclic<a class="headerlink" href="#cyclic" title="Permalink to this headline">#</a></h3>
<p>For Cyclic maps, we want to start and end on the same color, and meet a
symmetric center point in the middle. <span class="math notranslate nohighlight">\(L^*\)</span> should change monotonically
from start to middle, and inversely from middle to end. It should be symmetric
on the increasing and decreasing side, and only differ in hue. At the ends and
middle, <span class="math notranslate nohighlight">\(L^*\)</span> will reverse direction, which should be smoothed in
<span class="math notranslate nohighlight">\(L^*\)</span> space to reduce artifacts. See <a class="reference internal" href="#kovesi-colormaps" id="id5"><span>[kovesi-colormaps]</span></a> for more
information on the design of cyclic maps.</p>
<p>The often-used HSV colormap is included in this set of colormaps, although it
is not symmetric to a center point. Additionally, the <span class="math notranslate nohighlight">\(L^*\)</span> values vary
widely throughout the colormap, making it a poor choice for representing data
for viewers to see perceptually. See an extension on this idea at
<a class="reference internal" href="#mycarta-jet" id="id6"><span>[mycarta-jet]</span></a>.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">plot_color_gradients</span><span class="p">(</span><span class="s1">'Cyclic'</span><span class="p">,</span> <span class="p">[</span><span class="s1">'twilight'</span><span class="p">,</span> <span class="s1">'twilight_shifted'</span><span class="p">,</span> <span class="s1">'hsv'</span><span class="p">])</span>
</pre></div>
</div>
<img src="../../_images/sphx_glr_colormaps_005.png" srcset="../../_images/sphx_glr_colormaps_005.png, ../../_images/sphx_glr_colormaps_005_2_0x.png 2.0x" alt="Cyclic colormaps" class = "sphx-glr-single-img"/></section>
<section id="qualitative">
<h3>Qualitative<a class="headerlink" href="#qualitative" title="Permalink to this headline">#</a></h3>
<p>Qualitative colormaps are not aimed at being perceptual maps, but looking at the
lightness parameter can verify that for us. The <span class="math notranslate nohighlight">\(L^*\)</span> values move all over
the place throughout the colormap, and are clearly not monotonically increasing.
These would not be good options for use as perceptual colormaps.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">plot_color_gradients</span><span class="p">(</span><span class="s1">'Qualitative'</span><span class="p">,</span>
<span class="p">[</span><span class="s1">'Pastel1'</span><span class="p">,</span> <span class="s1">'Pastel2'</span><span class="p">,</span> <span class="s1">'Paired'</span><span class="p">,</span> <span class="s1">'Accent'</span><span class="p">,</span> <span class="s1">'Dark2'</span><span class="p">,</span>
<span class="s1">'Set1'</span><span class="p">,</span> <span class="s1">'Set2'</span><span class="p">,</span> <span class="s1">'Set3'</span><span class="p">,</span> <span class="s1">'tab10'</span><span class="p">,</span> <span class="s1">'tab20'</span><span class="p">,</span> <span class="s1">'tab20b'</span><span class="p">,</span>
<span class="s1">'tab20c'</span><span class="p">])</span>
</pre></div>
</div>
<img src="../../_images/sphx_glr_colormaps_006.png" srcset="../../_images/sphx_glr_colormaps_006.png, ../../_images/sphx_glr_colormaps_006_2_0x.png 2.0x" alt="Qualitative colormaps" class = "sphx-glr-single-img"/></section>
<section id="miscellaneous">
<h3>Miscellaneous<a class="headerlink" href="#miscellaneous" title="Permalink to this headline">#</a></h3>
<p>Some of the miscellaneous colormaps have particular uses for which
they have been created. For example, gist_earth, ocean, and terrain
all seem to be created for plotting topography (green/brown) and water
depths (blue) together. We would expect to see a divergence in these
colormaps, then, but multiple kinks may not be ideal, such as in
gist_earth and terrain. CMRmap was created to convert well to
grayscale, though it does appear to have some small kinks in
<span class="math notranslate nohighlight">\(L^*\)</span>. cubehelix was created to vary smoothly in both lightness
and hue, but appears to have a small hump in the green hue area. turbo
was created to display depth and disparity data.</p>
<p>The often-used jet colormap is included in this set of colormaps. We can see
that the <span class="math notranslate nohighlight">\(L^*\)</span> values vary widely throughout the colormap, making it a
poor choice for representing data for viewers to see perceptually. See an
extension on this idea at <a class="reference internal" href="#mycarta-jet" id="id7"><span>[mycarta-jet]</span></a> and <a class="reference internal" href="#turbo" id="id8"><span>[turbo]</span></a>.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">plot_color_gradients</span><span class="p">(</span><span class="s1">'Miscellaneous'</span><span class="p">,</span>
<span class="p">[</span><span class="s1">'flag'</span><span class="p">,</span> <span class="s1">'prism'</span><span class="p">,</span> <span class="s1">'ocean'</span><span class="p">,</span> <span class="s1">'gist_earth'</span><span class="p">,</span> <span class="s1">'terrain'</span><span class="p">,</span>
<span class="s1">'gist_stern'</span><span class="p">,</span> <span class="s1">'gnuplot'</span><span class="p">,</span> <span class="s1">'gnuplot2'</span><span class="p">,</span> <span class="s1">'CMRmap'</span><span class="p">,</span>
<span class="s1">'cubehelix'</span><span class="p">,</span> <span class="s1">'brg'</span><span class="p">,</span> <span class="s1">'gist_rainbow'</span><span class="p">,</span> <span class="s1">'rainbow'</span><span class="p">,</span> <span class="s1">'jet'</span><span class="p">,</span>
<span class="s1">'turbo'</span><span class="p">,</span> <span class="s1">'nipy_spectral'</span><span class="p">,</span> <span class="s1">'gist_ncar'</span><span class="p">])</span>
<a href="../../api/_as_gen/matplotlib.pyplot.show.html#matplotlib.pyplot.show" title="matplotlib.pyplot.show" 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">show</span></a><span class="p">()</span>
</pre></div>
</div>
<img src="../../_images/sphx_glr_colormaps_007.png" srcset="../../_images/sphx_glr_colormaps_007.png, ../../_images/sphx_glr_colormaps_007_2_0x.png 2.0x" alt="Miscellaneous colormaps" class = "sphx-glr-single-img"/></section>
</section>
<section id="lightness-of-matplotlib-colormaps">
<h2>Lightness of Matplotlib colormaps<a class="headerlink" href="#lightness-of-matplotlib-colormaps" title="Permalink to this headline">#</a></h2>
<p>Here we examine the lightness values of the matplotlib colormaps.
Note that some documentation on the colormaps is available
(<a class="reference internal" href="#list-colormaps" id="id9"><span>[list-colormaps]</span></a>).</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><a href="https://docs.python.org/3/library/stdtypes.html#dict.update" title="builtins.dict.update" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-method"><span class="n">mpl</span><span class="o">.</span><span class="n">rcParams</span><span class="o">.</span><span class="n">update</span></a><span class="p">({</span><span class="s1">'font.size'</span><span class="p">:</span> <span class="mi">12</span><span class="p">})</span>
<span class="c1"># Number of colormap per subplot for particular cmap categories</span>
<a href="https://docs.python.org/3/library/stdtypes.html#dict" title="builtins.dict" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">_DSUBS</span></a> <span class="o">=</span> <span class="p">{</span><span class="s1">'Perceptually Uniform Sequential'</span><span class="p">:</span> <span class="mi">5</span><span class="p">,</span> <span class="s1">'Sequential'</span><span class="p">:</span> <span class="mi">6</span><span class="p">,</span>
<span class="s1">'Sequential (2)'</span><span class="p">:</span> <span class="mi">6</span><span class="p">,</span> <span class="s1">'Diverging'</span><span class="p">:</span> <span class="mi">6</span><span class="p">,</span> <span class="s1">'Cyclic'</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span>
<span class="s1">'Qualitative'</span><span class="p">:</span> <span class="mi">4</span><span class="p">,</span> <span class="s1">'Miscellaneous'</span><span class="p">:</span> <span class="mi">6</span><span class="p">}</span>
<span class="c1"># Spacing between the colormaps of a subplot</span>
<a href="https://docs.python.org/3/library/stdtypes.html#dict" title="builtins.dict" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">_DC</span></a> <span class="o">=</span> <span class="p">{</span><span class="s1">'Perceptually Uniform Sequential'</span><span class="p">:</span> <span class="mf">1.4</span><span class="p">,</span> <span class="s1">'Sequential'</span><span class="p">:</span> <span class="mf">0.7</span><span class="p">,</span>
<span class="s1">'Sequential (2)'</span><span class="p">:</span> <span class="mf">1.4</span><span class="p">,</span> <span class="s1">'Diverging'</span><span class="p">:</span> <span class="mf">1.4</span><span class="p">,</span> <span class="s1">'Cyclic'</span><span class="p">:</span> <span class="mf">1.4</span><span class="p">,</span>
<span class="s1">'Qualitative'</span><span class="p">:</span> <span class="mf">1.4</span><span class="p">,</span> <span class="s1">'Miscellaneous'</span><span class="p">:</span> <span class="mf">1.4</span><span class="p">}</span>
<span class="c1"># Indices to step through colormap</span>
<a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">x</span></a> <span class="o">=</span> <a href="https://numpy.org/doc/stable/reference/generated/numpy.linspace.html#numpy.linspace" title="numpy.linspace" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-function"><span class="n">np</span><span class="o">.</span><span class="n">linspace</span></a><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span>
<span class="c1"># Do plot</span>
<span class="k">for</span> <a href="https://docs.python.org/3/library/stdtypes.html#str" title="builtins.str" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap_category</span></a><span class="p">,</span> <a href="https://docs.python.org/3/library/stdtypes.html#list" title="builtins.list" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap_list</span></a> <span class="ow">in</span> <a href="https://docs.python.org/3/library/stdtypes.html#dict" title="builtins.dict" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmaps</span></a><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="c1"># Do subplots so that colormaps have enough space.</span>
<span class="c1"># Default is 6 colormaps per subplot.</span>
<a href="https://docs.python.org/3/library/functions.html#int" title="builtins.int" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">dsub</span></a> <span class="o">=</span> <a href="https://docs.python.org/3/library/stdtypes.html#dict" title="builtins.dict" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">_DSUBS</span></a><span class="o">.</span><span class="n">get</span><span class="p">(</span><a href="https://docs.python.org/3/library/stdtypes.html#str" title="builtins.str" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap_category</span></a><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>
<a href="https://docs.python.org/3/library/functions.html#int" title="builtins.int" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">nsubplots</span></a> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><a href="https://numpy.org/doc/stable/reference/generated/numpy.ufunc.html#numpy.ufunc" title="numpy.ufunc" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">np</span><span class="o">.</span><span class="n">ceil</span></a><span class="p">(</span><span class="nb">len</span><span class="p">(</span><a href="https://docs.python.org/3/library/stdtypes.html#list" title="builtins.list" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap_list</span></a><span class="p">)</span> <span class="o">/</span> <a href="https://docs.python.org/3/library/functions.html#int" title="builtins.int" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">dsub</span></a><span class="p">))</span>
<span class="c1"># squeeze=False to handle similarly the case of a single subplot</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> <a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">axs</span></a> <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">nrows</span><span class="o">=</span><a href="https://docs.python.org/3/library/functions.html#int" title="builtins.int" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">nsubplots</span></a><span class="p">,</span> <span class="n">squeeze</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">7</span><span class="p">,</span> <span class="mf">2.6</span><span class="o">*</span><a href="https://docs.python.org/3/library/functions.html#int" title="builtins.int" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">nsubplots</span></a><span class="p">))</span>
<span class="k">for</span> <a href="https://docs.python.org/3/library/functions.html#int" title="builtins.int" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">i</span></a><span class="p">,</span> <span class="n">ax</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><a href="https://numpy.org/doc/stable/reference/generated/numpy.flatiter.html#numpy.flatiter" title="numpy.flatiter" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">axs</span><span class="o">.</span><span class="n">flat</span></a><span class="p">):</span>
<a href="https://docs.python.org/3/library/stdtypes.html#list" title="builtins.list" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">locs</span></a> <span class="o">=</span> <span class="p">[]</span> <span class="c1"># locations for text labels</span>
<span class="k">for</span> <a href="https://docs.python.org/3/library/functions.html#int" title="builtins.int" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">j</span></a><span class="p">,</span> <a href="https://docs.python.org/3/library/stdtypes.html#str" title="builtins.str" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap</span></a> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><a href="https://docs.python.org/3/library/stdtypes.html#list" title="builtins.list" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap_list</span></a><span class="p">[</span><a href="https://docs.python.org/3/library/functions.html#int" title="builtins.int" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">i</span></a><span class="o">*</span><a href="https://docs.python.org/3/library/functions.html#int" title="builtins.int" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">dsub</span></a><span class="p">:(</span><a href="https://docs.python.org/3/library/functions.html#int" title="builtins.int" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">i</span></a><span class="o">+</span><span class="mi">1</span><span class="p">)</span><span class="o">*</span><a href="https://docs.python.org/3/library/functions.html#int" title="builtins.int" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">dsub</span></a><span class="p">]):</span>
<span class="c1"># Get RGB values for colormap and convert the colormap in</span>
<span class="c1"># CAM02-UCS colorspace. lab[0, :, 0] is the lightness.</span>
<a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">rgb</span></a> <span class="o">=</span> <a href="../../api/cm_api.html#matplotlib.cm.get_cmap" title="matplotlib.cm.get_cmap" class="sphx-glr-backref-module-matplotlib-cm sphx-glr-backref-type-py-function"><span class="n">cm</span><span class="o">.</span><span class="n">get_cmap</span></a><span class="p">(</span><a href="https://docs.python.org/3/library/stdtypes.html#str" title="builtins.str" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap</span></a><span class="p">)(</span><a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">x</span></a><span class="p">)[</span><a href="https://numpy.org/doc/stable/reference/constants.html#numpy.newaxis" title="numpy.newaxis" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-data"><span class="n">np</span><span class="o">.</span><span class="n">newaxis</span></a><span class="p">,</span> <span class="p">:,</span> <span class="p">:</span><span class="mi">3</span><span class="p">]</span>
<a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">lab</span></a> <span class="o">=</span> <span class="n">cspace_converter</span><span class="p">(</span><span class="s2">"sRGB1"</span><span class="p">,</span> <span class="s2">"CAM02-UCS"</span><span class="p">)(</span><a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">rgb</span></a><span class="p">)</span>
<span class="c1"># Plot colormap L values. Do separately for each category</span>
<span class="c1"># so each plot can be pretty. To make scatter markers change</span>
<span class="c1"># color along plot:</span>
<span class="c1"># https://stackoverflow.com/q/8202605/</span>
<span class="k">if</span> <a href="https://docs.python.org/3/library/stdtypes.html#str" title="builtins.str" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap_category</span></a> <span class="o">==</span> <span class="s1">'Sequential'</span><span class="p">:</span>
<span class="c1"># These colormaps all start at high lightness but we want them</span>
<span class="c1"># reversed to look nice in the plot, so reverse the order.</span>
<a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">y_</span></a> <span class="o">=</span> <a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">lab</span></a><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="p">::</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">]</span>
<a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">c_</span></a> <span class="o">=</span> <a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">x</span></a><span class="p">[::</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
<a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">y_</span></a> <span class="o">=</span> <a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">lab</span></a><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="p">:,</span> <span class="mi">0</span><span class="p">]</span>
<a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">c_</span></a> <span class="o">=</span> <a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">x</span></a>
<a href="https://docs.python.org/3/library/functions.html#float" title="builtins.float" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">dc</span></a> <span class="o">=</span> <a href="https://docs.python.org/3/library/stdtypes.html#dict" title="builtins.dict" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">_DC</span></a><span class="o">.</span><span class="n">get</span><span class="p">(</span><a href="https://docs.python.org/3/library/stdtypes.html#str" title="builtins.str" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap_category</span></a><span class="p">,</span> <span class="mf">1.4</span><span class="p">)</span> <span class="c1"># cmaps horizontal spacing</span>
<a href="../../api/_as_gen/matplotlib.axes.Axes.scatter.html#matplotlib.axes.Axes.scatter" title="matplotlib.axes.Axes.scatter" 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">scatter</span></a><span class="p">(</span><a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">x</span></a> <span class="o">+</span> <a href="https://docs.python.org/3/library/functions.html#int" title="builtins.int" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">j</span></a><span class="o">*</span><a href="https://docs.python.org/3/library/functions.html#float" title="builtins.float" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">dc</span></a><span class="p">,</span> <a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">y_</span></a><span class="p">,</span> <span class="n">c</span><span class="o">=</span><a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">c_</span></a><span class="p">,</span> <a href="https://docs.python.org/3/library/stdtypes.html#str" title="builtins.str" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap</span></a><span class="o">=</span><a href="https://docs.python.org/3/library/stdtypes.html#str" title="builtins.str" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap</span></a><span class="p">,</span> <span class="n">s</span><span class="o">=</span><span class="mi">300</span><span class="p">,</span> <span class="n">linewidths</span><span class="o">=</span><span class="mf">0.0</span><span class="p">)</span>
<span class="c1"># Store locations for colormap labels</span>
<span class="k">if</span> <a href="https://docs.python.org/3/library/stdtypes.html#str" title="builtins.str" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap_category</span></a> <span class="ow">in</span> <span class="p">(</span><span class="s1">'Perceptually Uniform Sequential'</span><span class="p">,</span>
<span class="s1">'Sequential'</span><span class="p">):</span>
<a href="https://docs.python.org/3/library/stdtypes.html#list" title="builtins.list" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">locs</span></a><span class="o">.</span><span class="n">append</span><span class="p">(</span><a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">x</span></a><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <a href="https://docs.python.org/3/library/functions.html#int" title="builtins.int" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">j</span></a><span class="o">*</span><a href="https://docs.python.org/3/library/functions.html#float" title="builtins.float" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">dc</span></a><span class="p">)</span>
<span class="k">elif</span> <a href="https://docs.python.org/3/library/stdtypes.html#str" title="builtins.str" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap_category</span></a> <span class="ow">in</span> <span class="p">(</span><span class="s1">'Diverging'</span><span class="p">,</span> <span class="s1">'Qualitative'</span><span class="p">,</span> <span class="s1">'Cyclic'</span><span class="p">,</span>
<span class="s1">'Miscellaneous'</span><span class="p">,</span> <span class="s1">'Sequential (2)'</span><span class="p">):</span>
<a href="https://docs.python.org/3/library/stdtypes.html#list" title="builtins.list" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">locs</span></a><span class="o">.</span><span class="n">append</span><span class="p">(</span><a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">x</span></a><span class="p">[</span><span class="nb">int</span><span class="p">(</span><a href="https://docs.python.org/3/library/functions.html#int" title="builtins.int" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">x</span><span class="o">.</span><span class="n">size</span></a><span class="o">/</span><span class="mf">2.</span><span class="p">)]</span> <span class="o">+</span> <a href="https://docs.python.org/3/library/functions.html#int" title="builtins.int" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">j</span></a><span class="o">*</span><a href="https://docs.python.org/3/library/functions.html#float" title="builtins.float" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">dc</span></a><span class="p">)</span>
<span class="c1"># Set up the axis limits:</span>
<span class="c1"># * the 1st subplot is used as a reference for the x-axis limits</span>
<span class="c1"># * lightness values goes from 0 to 100 (y-axis limits)</span>
<a href="../../api/_as_gen/matplotlib.axes.Axes.set_xlim.html#matplotlib.axes.Axes.set_xlim" title="matplotlib.axes.Axes.set_xlim" 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">set_xlim</span></a><span class="p">(</span><a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">axs</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="o">.</span><span class="n">get_xlim</span><span class="p">())</span>
<a href="../../api/_as_gen/matplotlib.axes.Axes.set_ylim.html#matplotlib.axes.Axes.set_ylim" title="matplotlib.axes.Axes.set_ylim" 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">set_ylim</span></a><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">100.0</span><span class="p">)</span>
<span class="c1"># Set up labels for colormaps</span>
<a href="../../api/_as_gen/matplotlib.axis.XAxis.set_ticks_position.html#matplotlib.axis.XAxis.set_ticks_position" title="matplotlib.axis.XAxis.set_ticks_position" class="sphx-glr-backref-module-matplotlib-axis sphx-glr-backref-type-py-method"><span class="n">ax</span><span class="o">.</span><span class="n">xaxis</span><span class="o">.</span><span class="n">set_ticks_position</span></a><span class="p">(</span><span class="s1">'top'</span><span class="p">)</span>
<a href="../../api/ticker_api.html#matplotlib.ticker.FixedLocator" title="matplotlib.ticker.FixedLocator" class="sphx-glr-backref-module-matplotlib-ticker sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">ticker</span></a> <span class="o">=</span> <a href="../../api/ticker_api.html#matplotlib.ticker.FixedLocator" title="matplotlib.ticker.FixedLocator" class="sphx-glr-backref-module-matplotlib-ticker sphx-glr-backref-type-py-class"><span class="n">mpl</span><span class="o">.</span><span class="n">ticker</span><span class="o">.</span><span class="n">FixedLocator</span></a><span class="p">(</span><a href="https://docs.python.org/3/library/stdtypes.html#list" title="builtins.list" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">locs</span></a><span class="p">)</span>
<a href="../../api/_as_gen/matplotlib.axis.Axis.set_major_locator.html#matplotlib.axis.Axis.set_major_locator" title="matplotlib.axis.Axis.set_major_locator" class="sphx-glr-backref-module-matplotlib-axis sphx-glr-backref-type-py-method"><span class="n">ax</span><span class="o">.</span><span class="n">xaxis</span><span class="o">.</span><span class="n">set_major_locator</span></a><span class="p">(</span><a href="../../api/ticker_api.html#matplotlib.ticker.FixedLocator" title="matplotlib.ticker.FixedLocator" class="sphx-glr-backref-module-matplotlib-ticker sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">ticker</span></a><span class="p">)</span>
<a href="../../api/ticker_api.html#matplotlib.ticker.FixedFormatter" title="matplotlib.ticker.FixedFormatter" class="sphx-glr-backref-module-matplotlib-ticker sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">formatter</span></a> <span class="o">=</span> <a href="../../api/ticker_api.html#matplotlib.ticker.FixedFormatter" title="matplotlib.ticker.FixedFormatter" class="sphx-glr-backref-module-matplotlib-ticker sphx-glr-backref-type-py-class"><span class="n">mpl</span><span class="o">.</span><span class="n">ticker</span><span class="o">.</span><span class="n">FixedFormatter</span></a><span class="p">(</span><a href="https://docs.python.org/3/library/stdtypes.html#list" title="builtins.list" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap_list</span></a><span class="p">[</span><a href="https://docs.python.org/3/library/functions.html#int" title="builtins.int" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">i</span></a><span class="o">*</span><a href="https://docs.python.org/3/library/functions.html#int" title="builtins.int" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">dsub</span></a><span class="p">:(</span><a href="https://docs.python.org/3/library/functions.html#int" title="builtins.int" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">i</span></a><span class="o">+</span><span class="mi">1</span><span class="p">)</span><span class="o">*</span><a href="https://docs.python.org/3/library/functions.html#int" title="builtins.int" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">dsub</span></a><span class="p">])</span>
<a href="../../api/_as_gen/matplotlib.axis.Axis.set_major_formatter.html#matplotlib.axis.Axis.set_major_formatter" title="matplotlib.axis.Axis.set_major_formatter" class="sphx-glr-backref-module-matplotlib-axis sphx-glr-backref-type-py-method"><span class="n">ax</span><span class="o">.</span><span class="n">xaxis</span><span class="o">.</span><span class="n">set_major_formatter</span></a><span class="p">(</span><a href="../../api/ticker_api.html#matplotlib.ticker.FixedFormatter" title="matplotlib.ticker.FixedFormatter" class="sphx-glr-backref-module-matplotlib-ticker sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">formatter</span></a><span class="p">)</span>
<a href="../../api/_as_gen/matplotlib.axis.Axis.set_tick_params.html#matplotlib.axis.Axis.set_tick_params" title="matplotlib.axis.Axis.set_tick_params" class="sphx-glr-backref-module-matplotlib-axis sphx-glr-backref-type-py-method"><span class="n">ax</span><span class="o">.</span><span class="n">xaxis</span><span class="o">.</span><span class="n">set_tick_params</span></a><span class="p">(</span><span class="n">rotation</span><span class="o">=</span><span class="mi">50</span><span class="p">)</span>
<a href="../../api/_as_gen/matplotlib.axes.Axes.set_ylabel.html#matplotlib.axes.Axes.set_ylabel" title="matplotlib.axes.Axes.set_ylabel" 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">set_ylabel</span></a><span class="p">(</span><span class="s1">'Lightness $L^*$'</span><span class="p">,</span> <span class="n">fontsize</span><span class="o">=</span><span class="mi">12</span><span class="p">)</span>
<a href="../../api/_as_gen/matplotlib.axes.Axes.set_xlabel.html#matplotlib.axes.Axes.set_xlabel" title="matplotlib.axes.Axes.set_xlabel" 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">set_xlabel</span></a><span class="p">(</span><a href="https://docs.python.org/3/library/stdtypes.html#str" title="builtins.str" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap_category</span></a> <span class="o">+</span> <span class="s1">' colormaps'</span><span class="p">,</span> <span class="n">fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">)</span>
<a href="../../api/figure_api.html#matplotlib.figure.Figure.tight_layout" title="matplotlib.figure.Figure.tight_layout" class="sphx-glr-backref-module-matplotlib-figure sphx-glr-backref-type-py-method"><span class="n">fig</span><span class="o">.</span><span class="n">tight_layout</span></a><span class="p">(</span><span class="n">h_pad</span><span class="o">=</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">pad</span><span class="o">=</span><span class="mf">1.5</span><span class="p">)</span>
<a href="../../api/_as_gen/matplotlib.pyplot.show.html#matplotlib.pyplot.show" title="matplotlib.pyplot.show" 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">show</span></a><span class="p">()</span>
</pre></div>
</div>
<ul class="sphx-glr-horizontal">
<li><img src="../../_images/sphx_glr_colormaps_008.png" srcset="../../_images/sphx_glr_colormaps_008.png, ../../_images/sphx_glr_colormaps_008_2_0x.png 2.0x" alt="colormaps" class = "sphx-glr-multi-img"/></li>
<li><img src="../../_images/sphx_glr_colormaps_009.png" srcset="../../_images/sphx_glr_colormaps_009.png, ../../_images/sphx_glr_colormaps_009_2_0x.png 2.0x" alt="colormaps" class = "sphx-glr-multi-img"/></li>
<li><img src="../../_images/sphx_glr_colormaps_010.png" srcset="../../_images/sphx_glr_colormaps_010.png, ../../_images/sphx_glr_colormaps_010_2_0x.png 2.0x" alt="colormaps" class = "sphx-glr-multi-img"/></li>
<li><img src="../../_images/sphx_glr_colormaps_011.png" srcset="../../_images/sphx_glr_colormaps_011.png, ../../_images/sphx_glr_colormaps_011_2_0x.png 2.0x" alt="colormaps" class = "sphx-glr-multi-img"/></li>
<li><img src="../../_images/sphx_glr_colormaps_012.png" srcset="../../_images/sphx_glr_colormaps_012.png, ../../_images/sphx_glr_colormaps_012_2_0x.png 2.0x" alt="colormaps" class = "sphx-glr-multi-img"/></li>
<li><img src="../../_images/sphx_glr_colormaps_013.png" srcset="../../_images/sphx_glr_colormaps_013.png, ../../_images/sphx_glr_colormaps_013_2_0x.png 2.0x" alt="colormaps" class = "sphx-glr-multi-img"/></li>
<li><img src="../../_images/sphx_glr_colormaps_014.png" srcset="../../_images/sphx_glr_colormaps_014.png, ../../_images/sphx_glr_colormaps_014_2_0x.png 2.0x" alt="colormaps" class = "sphx-glr-multi-img"/></li>
</ul>
</section>
<section id="grayscale-conversion">
<h2>Grayscale conversion<a class="headerlink" href="#grayscale-conversion" title="Permalink to this headline">#</a></h2>
<p>It is important to pay attention to conversion to grayscale for color
plots, since they may be printed on black and white printers. If not
carefully considered, your readers may end up with indecipherable
plots because the grayscale changes unpredictably through the
colormap.</p>
<p>Conversion to grayscale is done in many different ways <a class="reference internal" href="#bw" id="id10"><span>[bw]</span></a>. Some of the
better ones use a linear combination of the rgb values of a pixel, but
weighted according to how we perceive color intensity. A nonlinear method of
conversion to grayscale is to use the <span class="math notranslate nohighlight">\(L^*\)</span> values of the pixels. In
general, similar principles apply for this question as they do for presenting
one's information perceptually; that is, if a colormap is chosen that is
monotonically increasing in <span class="math notranslate nohighlight">\(L^*\)</span> values, it will print in a reasonable
manner to grayscale.</p>
<p>With this in mind, we see that the Sequential colormaps have reasonable
representations in grayscale. Some of the Sequential2 colormaps have decent
enough grayscale representations, though some (autumn, spring, summer,
winter) have very little grayscale change. If a colormap like this was used
in a plot and then the plot was printed to grayscale, a lot of the
information may map to the same gray values. The Diverging colormaps mostly
vary from darker gray on the outer edges to white in the middle. Some
(PuOr and seismic) have noticeably darker gray on one side than the other
and therefore are not very symmetric. coolwarm has little range of gray scale
and would print to a more uniform plot, losing a lot of detail. Note that
overlaid, labeled contours could help differentiate between one side of the
colormap vs. the other since color cannot be used once a plot is printed to
grayscale. Many of the Qualitative and Miscellaneous colormaps, such as
Accent, hsv, jet and turbo, change from darker to lighter and back to darker
grey throughout the colormap. This would make it impossible for a viewer to
interpret the information in a plot once it is printed in grayscale.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><a href="https://docs.python.org/3/library/stdtypes.html#dict.update" title="builtins.dict.update" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-method"><span class="n">mpl</span><span class="o">.</span><span class="n">rcParams</span><span class="o">.</span><span class="n">update</span></a><span class="p">({</span><span class="s1">'font.size'</span><span class="p">:</span> <span class="mi">14</span><span class="p">})</span>
<span class="c1"># Indices to step through colormap.</span>
<a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">x</span></a> <span class="o">=</span> <a href="https://numpy.org/doc/stable/reference/generated/numpy.linspace.html#numpy.linspace" title="numpy.linspace" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-function"><span class="n">np</span><span class="o">.</span><span class="n">linspace</span></a><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span>
<a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">gradient</span></a> <span class="o">=</span> <a href="https://numpy.org/doc/stable/reference/generated/numpy.linspace.html#numpy.linspace" title="numpy.linspace" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-function"><span class="n">np</span><span class="o">.</span><span class="n">linspace</span></a><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">256</span><span class="p">)</span>
<a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">gradient</span></a> <span class="o">=</span> <a href="https://numpy.org/doc/stable/reference/generated/numpy.vstack.html#numpy.vstack" title="numpy.vstack" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-function"><span class="n">np</span><span class="o">.</span><span class="n">vstack</span></a><span class="p">((</span><a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">gradient</span></a><span class="p">,</span> <a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">gradient</span></a><span class="p">))</span>
<span class="k">def</span> <span class="nf">plot_color_gradients</span><span class="p">(</span><a href="https://docs.python.org/3/library/stdtypes.html#str" title="builtins.str" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap_category</span></a><span class="p">,</span> <a href="https://docs.python.org/3/library/stdtypes.html#list" title="builtins.list" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap_list</span></a><span class="p">):</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> <a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">axs</span></a> <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">nrows</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><a href="https://docs.python.org/3/library/stdtypes.html#list" title="builtins.list" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap_list</span></a><span class="p">),</span> <span class="n">ncols</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
<a href="../../api/figure_api.html#matplotlib.figure.Figure.subplots_adjust" title="matplotlib.figure.Figure.subplots_adjust" class="sphx-glr-backref-module-matplotlib-figure sphx-glr-backref-type-py-method"><span class="n">fig</span><span class="o">.</span><span class="n">subplots_adjust</span></a><span class="p">(</span><span class="n">top</span><span class="o">=</span><span class="mf">0.95</span><span class="p">,</span> <span class="n">bottom</span><span class="o">=</span><span class="mf">0.01</span><span class="p">,</span> <span class="n">left</span><span class="o">=</span><span class="mf">0.2</span><span class="p">,</span> <span class="n">right</span><span class="o">=</span><span class="mf">0.99</span><span class="p">,</span>
<span class="n">wspace</span><span class="o">=</span><span class="mf">0.05</span><span class="p">)</span>
<a href="../../api/figure_api.html#matplotlib.figure.Figure.suptitle" title="matplotlib.figure.Figure.suptitle" class="sphx-glr-backref-module-matplotlib-figure sphx-glr-backref-type-py-method"><span class="n">fig</span><span class="o">.</span><span class="n">suptitle</span></a><span class="p">(</span><a href="https://docs.python.org/3/library/stdtypes.html#str" title="builtins.str" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap_category</span></a> <span class="o">+</span> <span class="s1">' colormaps'</span><span class="p">,</span> <span class="n">fontsize</span><span class="o">=</span><span class="mi">14</span><span class="p">,</span> <span class="n">y</span><span class="o">=</span><span class="mf">1.0</span><span class="p">,</span> <a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">x</span></a><span class="o">=</span><span class="mf">0.6</span><span class="p">)</span>
<span class="k">for</span> <span class="n">ax</span><span class="p">,</span> <span class="n">name</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">axs</span></a><span class="p">,</span> <a href="https://docs.python.org/3/library/stdtypes.html#list" title="builtins.list" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap_list</span></a><span class="p">):</span>
<span class="c1"># Get RGB values for colormap.</span>
<a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">rgb</span></a> <span class="o">=</span> <a href="../../api/cm_api.html#matplotlib.cm.get_cmap" title="matplotlib.cm.get_cmap" class="sphx-glr-backref-module-matplotlib-cm sphx-glr-backref-type-py-function"><span class="n">cm</span><span class="o">.</span><span class="n">get_cmap</span></a><span class="p">(</span><span class="n">plt</span><span class="o">.</span><span class="n">get_cmap</span><span class="p">(</span><span class="n">name</span><span class="p">))(</span><a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">x</span></a><span class="p">)[</span><a href="https://numpy.org/doc/stable/reference/constants.html#numpy.newaxis" title="numpy.newaxis" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-data"><span class="n">np</span><span class="o">.</span><span class="n">newaxis</span></a><span class="p">,</span> <span class="p">:,</span> <span class="p">:</span><span class="mi">3</span><span class="p">]</span>
<span class="c1"># Get colormap in CAM02-UCS colorspace. We want the lightness.</span>
<a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">lab</span></a> <span class="o">=</span> <span class="n">cspace_converter</span><span class="p">(</span><span class="s2">"sRGB1"</span><span class="p">,</span> <span class="s2">"CAM02-UCS"</span><span class="p">)(</span><a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">rgb</span></a><span class="p">)</span>
<span class="n">L</span> <span class="o">=</span> <a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">lab</span></a><span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="p">:,</span> <span class="mi">0</span><span class="p">]</span>
<span class="n">L</span> <span class="o">=</span> <a href="https://numpy.org/doc/stable/reference/arrays.scalars.html#numpy.float32" title="numpy.float32" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-attribute"><span class="n">np</span><span class="o">.</span><span class="n">float32</span></a><span class="p">(</span><a href="https://numpy.org/doc/stable/reference/generated/numpy.vstack.html#numpy.vstack" title="numpy.vstack" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-function"><span class="n">np</span><span class="o">.</span><span class="n">vstack</span></a><span class="p">((</span><span class="n">L</span><span class="p">,</span> <span class="n">L</span><span class="p">,</span> <span class="n">L</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">imshow</span><span class="p">(</span><a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray" title="numpy.ndarray" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">gradient</span></a><span class="p">,</span> <span class="n">aspect</span><span class="o">=</span><span class="s1">'auto'</span><span class="p">,</span> <a href="https://docs.python.org/3/library/stdtypes.html#str" title="builtins.str" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap</span></a><span class="o">=</span><span class="n">plt</span><span class="o">.</span><span class="n">get_cmap</span><span class="p">(</span><span class="n">name</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">imshow</span><span class="p">(</span><span class="n">L</span><span class="p">,</span> <span class="n">aspect</span><span class="o">=</span><span class="s1">'auto'</span><span class="p">,</span> <a href="https://docs.python.org/3/library/stdtypes.html#str" title="builtins.str" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap</span></a><span class="o">=</span><span class="s1">'binary_r'</span><span class="p">,</span> <span class="n">vmin</span><span class="o">=</span><span class="mf">0.</span><span class="p">,</span> <span class="n">vmax</span><span class="o">=</span><span class="mf">100.</span><span class="p">)</span>
<span class="n">pos</span> <span class="o">=</span> <span class="nb">list</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">get_position</span><span class="p">()</span><span class="o">.</span><span class="n">bounds</span><span class="p">)</span>
<span class="n">x_text</span> <span class="o">=</span> <span class="n">pos</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="mf">0.01</span>
<span class="n">y_text</span> <span class="o">=</span> <span class="n">pos</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="n">pos</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span><span class="o">/</span><span class="mf">2.</span>
<a href="../../api/figure_api.html#matplotlib.figure.Figure.text" title="matplotlib.figure.Figure.text" class="sphx-glr-backref-module-matplotlib-figure sphx-glr-backref-type-py-method"><span class="n">fig</span><span class="o">.</span><span class="n">text</span></a><span class="p">(</span><span class="n">x_text</span><span class="p">,</span> <span class="n">y_text</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">va</span><span class="o">=</span><span class="s1">'center'</span><span class="p">,</span> <span class="n">ha</span><span class="o">=</span><span class="s1">'right'</span><span class="p">,</span> <span class="n">fontsize</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
<span class="c1"># Turn off *all* ticks & spines, not just the ones with colormaps.</span>
<span class="k">for</span> <span class="n">ax</span> <span class="ow">in</span> <a href="https://numpy.org/doc/stable/reference/generated/numpy.flatiter.html#numpy.flatiter" title="numpy.flatiter" class="sphx-glr-backref-module-numpy sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">axs</span><span class="o">.</span><span class="n">flat</span></a><span class="p">:</span>
<a href="../../api/_as_gen/matplotlib.axes.Axes.set_axis_off.html#matplotlib.axes.Axes.set_axis_off" title="matplotlib.axes.Axes.set_axis_off" 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">set_axis_off</span></a><span class="p">()</span>
<a href="../../api/_as_gen/matplotlib.pyplot.show.html#matplotlib.pyplot.show" title="matplotlib.pyplot.show" 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">show</span></a><span class="p">()</span>
<span class="k">for</span> <a href="https://docs.python.org/3/library/stdtypes.html#str" title="builtins.str" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap_category</span></a><span class="p">,</span> <a href="https://docs.python.org/3/library/stdtypes.html#list" title="builtins.list" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap_list</span></a> <span class="ow">in</span> <a href="https://docs.python.org/3/library/stdtypes.html#dict" title="builtins.dict" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmaps</span></a><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="n">plot_color_gradients</span><span class="p">(</span><a href="https://docs.python.org/3/library/stdtypes.html#str" title="builtins.str" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap_category</span></a><span class="p">,</span> <a href="https://docs.python.org/3/library/stdtypes.html#list" title="builtins.list" class="sphx-glr-backref-module-builtins sphx-glr-backref-type-py-class sphx-glr-backref-instance"><span class="n">cmap_list</span></a><span class="p">)</span>
</pre></div>
</div>
<ul class="sphx-glr-horizontal">
<li><img src="../../_images/sphx_glr_colormaps_015.png" srcset="../../_images/sphx_glr_colormaps_015.png, ../../_images/sphx_glr_colormaps_015_2_0x.png 2.0x" alt="Perceptually Uniform Sequential colormaps" class = "sphx-glr-multi-img"/></li>
<li><img src="../../_images/sphx_glr_colormaps_016.png" srcset="../../_images/sphx_glr_colormaps_016.png, ../../_images/sphx_glr_colormaps_016_2_0x.png 2.0x" alt="Sequential colormaps" class = "sphx-glr-multi-img"/></li>
<li><img src="../../_images/sphx_glr_colormaps_017.png" srcset="../../_images/sphx_glr_colormaps_017.png, ../../_images/sphx_glr_colormaps_017_2_0x.png 2.0x" alt="Sequential (2) colormaps" class = "sphx-glr-multi-img"/></li>
<li><img src="../../_images/sphx_glr_colormaps_018.png" srcset="../../_images/sphx_glr_colormaps_018.png, ../../_images/sphx_glr_colormaps_018_2_0x.png 2.0x" alt="Diverging colormaps" class = "sphx-glr-multi-img"/></li>
<li><img src="../../_images/sphx_glr_colormaps_019.png" srcset="../../_images/sphx_glr_colormaps_019.png, ../../_images/sphx_glr_colormaps_019_2_0x.png 2.0x" alt="Cyclic colormaps" class = "sphx-glr-multi-img"/></li>
<li><img src="../../_images/sphx_glr_colormaps_020.png" srcset="../../_images/sphx_glr_colormaps_020.png, ../../_images/sphx_glr_colormaps_020_2_0x.png 2.0x" alt="Qualitative colormaps" class = "sphx-glr-multi-img"/></li>
<li><img src="../../_images/sphx_glr_colormaps_021.png" srcset="../../_images/sphx_glr_colormaps_021.png, ../../_images/sphx_glr_colormaps_021_2_0x.png 2.0x" alt="Miscellaneous colormaps" class = "sphx-glr-multi-img"/></li>
</ul>
</section>
<section id="color-vision-deficiencies">
<h2>Color vision deficiencies<a class="headerlink" href="#color-vision-deficiencies" title="Permalink to this headline">#</a></h2>
<p>There is a lot of information available about color blindness (<em>e.g.</em>,
<a class="reference internal" href="#colorblindness" id="id11"><span>[colorblindness]</span></a>). Additionally, there are tools available to convert images
to how they look for different types of color vision deficiencies.</p>
<p>The most common form of color vision deficiency involves differentiating
between red and green. Thus, avoiding colormaps with both red and green will
avoid many problems in general.</p>
</section>
<section id="references">
<h2>References<a class="headerlink" href="#references" title="Permalink to this headline">#</a></h2>
<dl class="citation">
<dt class="label" id="ware"><span class="brackets"><a class="fn-backref" href="#id1">Ware</a></span></dt>
<dd><p><a class="reference external" href="http://ccom.unh.edu/sites/default/files/publications/Ware_1988_CGA_Color_sequences_univariate_maps.pdf">http://ccom.unh.edu/sites/default/files/publications/Ware_1988_CGA_Color_sequences_univariate_maps.pdf</a></p>
</dd>
<dt class="label" id="moreland"><span class="brackets"><a class="fn-backref" href="#id3">Moreland</a></span></dt>
<dd><p><a class="reference external" href="http://www.kennethmoreland.com/color-maps/ColorMapsExpanded.pdf">http://www.kennethmoreland.com/color-maps/ColorMapsExpanded.pdf</a></p>
</dd>
<dt class="label" id="list-colormaps"><span class="brackets"><a class="fn-backref" href="#id9">list-colormaps</a></span></dt>
<dd><p><a class="reference external" href="https://gist.github.com/endolith/2719900#id7">https://gist.github.com/endolith/2719900#id7</a></p>
</dd>
<dt class="label" id="mycarta-banding"><span class="brackets"><a class="fn-backref" href="#id4">mycarta-banding</a></span></dt>
<dd><p><a class="reference external" href="https://mycarta.wordpress.com/2012/10/14/the-rainbow-is-deadlong-live-the-rainbow-part-4-cie-lab-heated-body/">https://mycarta.wordpress.com/2012/10/14/the-rainbow-is-deadlong-live-the-rainbow-part-4-cie-lab-heated-body/</a></p>
</dd>
<dt class="label" id="mycarta-jet"><span class="brackets">mycarta-jet</span><span class="fn-backref">(<a href="#id6">1</a>,<a href="#id7">2</a>)</span></dt>
<dd><p><a class="reference external" href="https://mycarta.wordpress.com/2012/10/06/the-rainbow-is-deadlong-live-the-rainbow-part-3/">https://mycarta.wordpress.com/2012/10/06/the-rainbow-is-deadlong-live-the-rainbow-part-3/</a></p>
</dd>
<dt class="label" id="kovesi-colormaps"><span class="brackets"><a class="fn-backref" href="#id5">kovesi-colormaps</a></span></dt>
<dd><p><a class="reference external" href="https://arxiv.org/abs/1509.03700">https://arxiv.org/abs/1509.03700</a></p>
</dd>
<dt class="label" id="bw"><span class="brackets"><a class="fn-backref" href="#id10">bw</a></span></dt>
<dd><p><a class="reference external" href="https://tannerhelland.com/3643/grayscale-image-algorithm-vb6/">https://tannerhelland.com/3643/grayscale-image-algorithm-vb6/</a></p>
</dd>
<dt class="label" id="colorblindness"><span class="brackets"><a class="fn-backref" href="#id11">colorblindness</a></span></dt>
<dd><p><a class="reference external" href="http://www.color-blindness.com/">http://www.color-blindness.com/</a></p>
</dd>
<dt class="label" id="ibm"><span class="brackets"><a class="fn-backref" href="#id2">IBM</a></span></dt>
<dd><p><a class="reference external" href="https://doi.org/10.1109/VISUAL.1995.480803">https://doi.org/10.1109/VISUAL.1995.480803</a></p>
</dd>
<dt class="label" id="turbo"><span class="brackets"><a class="fn-backref" href="#id8">turbo</a></span></dt>
<dd><p><a class="reference external" href="https://ai.googleblog.com/2019/08/turbo-improved-rainbow-colormap-for.html">https://ai.googleblog.com/2019/08/turbo-improved-rainbow-colormap-for.html</a></p>
</dd>
</dl>
<p class="sphx-glr-timing"><strong>Total running time of the script:</strong> ( 0 minutes 14.164 seconds)</p>
<div class="sphx-glr-footer class sphx-glr-footer-example docutils container" id="sphx-glr-download-tutorials-colors-colormaps-py">
<div class="sphx-glr-download sphx-glr-download-python docutils container">
<p><a class="reference download internal" download="" href="../../_downloads/d4718022be2010da0684c60371f4593a/colormaps.py"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Python</span> <span class="pre">source</span> <span class="pre">code:</span> <span class="pre">colormaps.py</span></code></a></p>
</div>
<div class="sphx-glr-download sphx-glr-download-jupyter docutils container">
<p><a class="reference download internal" download="" href="../../_downloads/be2939a518dab831c4d343d142e6c9f1/colormaps.ipynb"><code class="xref download docutils literal notranslate"><span class="pre">Download</span> <span class="pre">Jupyter</span> <span class="pre">notebook:</span> <span class="pre">colormaps.ipynb</span></code></a></p>
</div>
</div>
<p class="sphx-glr-signature">Keywords: matplotlib code example, codex, python plot, pyplot
<a class="reference external" href="https://sphinx-gallery.readthedocs.io">Gallery generated by Sphinx-Gallery</a></p>
</section>
</section>
</div>
</main>
</div>
</div>
<!-- Scripts loaded after <body> so the DOM is not blocked -->
<div id="unreleased-message"> You are reading an old version of the documentation (v3.5.2). For the latest version see <a href="https://matplotlib.org/stable/tutorials/colors/colormaps.html">https://matplotlib.org/stable/tutorials/colors/colormaps.html</a></div>
<script src="../../_static/scripts/pydata-sphinx-theme.js?digest=1999514e3f237ded88cf"></script>
<footer class="footer mt-5 mt-md-0">
<div class="container">
<div class="footer-item">
<p class="copyright">
© Copyright 2002 - 2012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom and the Matplotlib development team; 2012 - 2022 The Matplotlib development team.<br>
</p>
</div>
<div class="footer-item">
<p class="sphinx-version">
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 4.5.0.<br>
</p>
</div>
</div>
</footer>