-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathcolormaps.html
More file actions
667 lines (608 loc) · 92.5 KB
/
colormaps.html
File metadata and controls
667 lines (608 loc) · 92.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
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
<!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" />
<title>Choosing Colormaps in Matplotlib — Matplotlib 3.2.0 documentation</title>
<link rel="stylesheet" href="../../_static/mpl.css?v3.2.0-3-gea62ccde8" type="text/css" />
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="../../_static/graphviz.css" />
<link rel="stylesheet" type="text/css" href="../../_static/gallery.css" />
<link rel="stylesheet" type="text/css" href="../../_static/copybutton.css" />
<script id="documentation_options" data-url_root="../../" 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/language_data.js"></script>
<script src="../../_static/clipboard.min.js"></script>
<script src="../../_static/copybutton.js"></script>
<script >var copybuttonSkipText = '>>> ';</script>
<script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Matplotlib 3.2.0 documentation"
href="../../_static/opensearch.xml"/>
<link rel="shortcut icon" href="../../_static/favicon.ico"/>
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
<link rel="next" title="Text in Matplotlib Plots" href="../text/text_intro.html" />
<link rel="prev" title="Colormap Normalization" href="colormapnorms.html" />
<link rel="top" title="Matplotlib 3.2.0 documentation" href="#" />
<link rel="canonical" href="https://matplotlib.org/stable/tutorials/colors/colormaps.html" />
<link rel="stylesheet" href="../../_static/custom.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
<script data-domain="matplotlib.org" defer="defer" src="https://views.scientific-python.org/js/script.js"></script>
</head><body>
<div id="unreleased-message"> You are reading an old version of the documentation (v3.2.0). 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>
<div style="background-color: white; text-align: left; padding: 10px 10px 15px 15px; position: relative;">
<a href="../../index.html">
<div style="float: left; position: absolute; width: 496px; bottom: 0; padding-bottom: 24px"><span style="float: right; color: #789; background: white">Version 3.2.0</span></div>
<img src="../../_static/logo2_compressed.svg" height="125px" border="0" alt="matplotlib"/></a>
<!-- The "Fork me on github" ribbon -->
<div id="forkongithub"><a href="https://github.com/matplotlib/matplotlib">Fork me on GitHub</a></div>
</div>
<nav class="main-nav">
<ul>
<li><a href="../../users/installing.html">Installation</a></li>
<li><a href="../../contents.html">Documentation</a></li>
<li><a href="../../gallery/index.html">Examples</a></li>
<li><a href="../index.html">Tutorials</a></li>
<li><a href="../../devel/index.html">Contributing</a></li>
<li class="nav-right">
<form class="search" action="../../search.html" method="get">
<input type="text" name="q" aria-labelledby="searchlabel" placeholder="Search"/>
</form>
</li>
</ul>
</nav>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="../text/text_intro.html" title="Text in Matplotlib Plots"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="colormapnorms.html" title="Colormap Normalization"
accesskey="P">previous</a> |</li>
<li><a href="../../index.html">home</a>| </li>
<li><a href="../../contents.html">contents</a> »</li>
<li class="nav-item nav-item-1"><a href="../../users/index.html" >User's Guide</a> »</li>
<li class="nav-item nav-item-2"><a href="../index.html" accesskey="U">Tutorials</a> »</li>
</ul>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Choosing Colormaps in Matplotlib</a><ul>
<li><a class="reference internal" href="#overview">Overview</a></li>
<li><a class="reference internal" href="#classes-of-colormaps">Classes of colormaps</a><ul>
<li><a class="reference internal" href="#sequential">Sequential</a></li>
<li><a class="reference internal" href="#sequential2">Sequential2</a></li>
<li><a class="reference internal" href="#diverging">Diverging</a></li>
<li><a class="reference internal" href="#cyclic">Cyclic</a></li>
<li><a class="reference internal" href="#qualitative">Qualitative</a></li>
<li><a class="reference internal" href="#miscellaneous">Miscellaneous</a></li>
</ul>
</li>
<li><a class="reference internal" href="#lightness-of-matplotlib-colormaps">Lightness of matplotlib colormaps</a></li>
<li><a class="reference internal" href="#grayscale-conversion">Grayscale conversion</a></li>
<li><a class="reference internal" href="#color-vision-deficiencies">Color vision deficiencies</a></li>
<li><a class="reference internal" href="#references">References</a></li>
</ul>
</li>
</ul>
<div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="../../contents.html">Documentation overview</a><ul>
<li><a href="../../users/index.html">User's Guide</a><ul>
<li><a href="../index.html">Tutorials</a><ul>
<li>Previous: <a href="colormapnorms.html" title="previous chapter">Colormap Normalization</a></li>
<li>Next: <a href="../text/text_intro.html" title="next chapter">Text in Matplotlib Plots</a></li>
</ul></li>
</ul></li>
</ul></li>
</ul>
</div>
<div id="sidebar-pagesource" role="note" aria-label="source link"
style="margin-top: 1.5em; padding-top: 0.1em; border-top: 1px solid #86989b">
<a href="../../_sources/tutorials/colors/colormaps.rst.txt"
style="color: #c0c0c0" rel="nofollow">Show Page Source</a>
</div>
</div>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="sphx-glr-download-link-note admonition note">
<p class="first admonition-title">Note</p>
<p class="last">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>
<div class="sphx-glr-example-title section" 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 like
<a class="reference internal" href="#palettable" id="id1"><span>[palettable]</span></a> and <a class="reference internal" href="#colorcet" id="id2"><span>[colorcet]</span></a> that have many extra colormaps.
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>
<div class="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>Whether representing form or metric data (<a class="reference internal" href="#ware" id="id3"><span>[Ware]</span></a>)</li>
<li>Your knowledge of the data set (<em>e.g.</em>, is there a critical value
from which the other values deviate?)</li>
<li>If there is an intuitive color scheme for the parameter you are plotting</li>
<li>If there is a standard in the field the audience may be expecting</li>
</ul>
<p>For many applications, a perceptually uniform colormap is the best
choice --- one 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. A wonderful example of
perceptually uniform colormaps is <a class="reference internal" href="#colorcet" id="id4"><span>[colorcet]</span></a>.</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="id5"><span>[IBM]</span></a>.</p>
</div>
<div class="section" id="classes-of-colormaps">
<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="id6"><span>[Moreland]</span></a>):</p>
<ol class="arabic simple">
<li>Sequential: change in lightness and often saturation of color
incrementally, often using a single hue; should be used for
representing information that has ordering.</li>
<li>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.</li>
<li>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.</li>
<li>Qualitative: often are miscellaneous colors; should be used to
represent information which does not have ordering or
relationships.</li>
</ol>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># sphinx_gallery_thumbnail_number = 2</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>
<span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <a href="https://docs.python.org/3/library/collections.html#collections.OrderedDict" title="View documentation for collections.OrderedDict"><span class="n">OrderedDict</span></a>
<a href="https://docs.python.org/3/library/collections.html#collections.OrderedDict" title="View documentation for collections.OrderedDict"><span class="n">cmaps</span></a> <span class="o">=</span> <a href="https://docs.python.org/3/library/collections.html#collections.OrderedDict" title="View documentation for collections.OrderedDict"><span class="n">OrderedDict</span></a><span class="p">()</span>
</pre></div>
</div>
<div class="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><a href="https://docs.python.org/3/library/collections.html#collections.OrderedDict" title="View documentation for collections.OrderedDict"><span class="n">cmaps</span></a><span class="p">[</span><span class="s1">'Perceptually Uniform Sequential'</span><span class="p">]</span> <span class="o">=</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>
<a href="https://docs.python.org/3/library/collections.html#collections.OrderedDict" title="View documentation for collections.OrderedDict"><span class="n">cmaps</span></a><span class="p">[</span><span class="s1">'Sequential'</span><span class="p">]</span> <span class="o">=</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>
</div>
<div class="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="id7"><span>[mycarta-banding]</span></a> for
an excellent example of this).</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><a href="https://docs.python.org/3/library/collections.html#collections.OrderedDict" title="View documentation for collections.OrderedDict"><span class="n">cmaps</span></a><span class="p">[</span><span class="s1">'Sequential (2)'</span><span class="p">]</span> <span class="o">=</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>
</div>
<div class="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><a href="https://docs.python.org/3/library/collections.html#collections.OrderedDict" title="View documentation for collections.OrderedDict"><span class="n">cmaps</span></a><span class="p">[</span><span class="s1">'Diverging'</span><span class="p">]</span> <span class="o">=</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>
</div>
<div class="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="id8"><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="id9"><span>[mycarta-jet]</span></a>.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><a href="https://docs.python.org/3/library/collections.html#collections.OrderedDict" title="View documentation for collections.OrderedDict"><span class="n">cmaps</span></a><span class="p">[</span><span class="s1">'Cyclic'</span><span class="p">]</span> <span class="o">=</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>
</div>
<div class="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><a href="https://docs.python.org/3/library/collections.html#collections.OrderedDict" title="View documentation for collections.OrderedDict"><span class="n">cmaps</span></a><span class="p">[</span><span class="s1">'Qualitative'</span><span class="p">]</span> <span class="o">=</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>
</div>
<div class="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.</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="id10"><span>[mycarta-jet]</span></a>.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><a href="https://docs.python.org/3/library/collections.html#collections.OrderedDict" title="View documentation for collections.OrderedDict"><span class="n">cmaps</span></a><span class="p">[</span><span class="s1">'Miscellaneous'</span><span class="p">]</span> <span class="o">=</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">'nipy_spectral'</span><span class="p">,</span> <span class="s1">'gist_ncar'</span><span class="p">]</span>
</pre></div>
</div>
<p id="color-colormaps-reference">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/functions.html#int" title="View documentation for builtins.int"><span class="n">nrows</span></a> <span class="o">=</span> <span class="nb">max</span><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="View documentation for builtins.list"><span class="n">cmap_list</span></a><span class="p">)</span> <span class="k">for</span> <a href="https://docs.python.org/3/library/stdtypes.html#str" title="View documentation for builtins.str"><span class="n">cmap_category</span></a><span class="p">,</span> <a href="https://docs.python.org/3/library/stdtypes.html#list" title="View documentation for builtins.list"><span class="n">cmap_list</span></a> <span class="ow">in</span> <a href="https://docs.python.org/3/library/collections.html#collections.OrderedDict" title="View documentation for collections.OrderedDict"><span class="n">cmaps</span></a><span class="o">.</span><span class="n">items</span><span class="p">())</span>
<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">gradient</span></a> <span class="o">=</span> <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.linspace.html#numpy.linspace" title="View documentation for numpy.linspace"><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://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">gradient</span></a> <span class="o">=</span> <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.vstack.html#numpy.vstack" title="View documentation for numpy.vstack"><span class="n">np</span><span class="o">.</span><span class="n">vstack</span></a><span class="p">((</span><a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">gradient</span></a><span class="p">,</span> <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><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="View documentation for builtins.str"><span class="n">cmap_category</span></a><span class="p">,</span> <a href="https://docs.python.org/3/library/stdtypes.html#list" title="View documentation for builtins.list"><span class="n">cmap_list</span></a><span class="p">,</span> <a href="https://docs.python.org/3/library/functions.html#int" title="View documentation for builtins.int"><span class="n">nrows</span></a><span class="p">):</span>
<a href="../../api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure" title="View documentation for matplotlib.figure.Figure"><span class="n">fig</span></a><span class="p">,</span> <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">axes</span></a> <span class="o">=</span> <a href="../../api/_as_gen/matplotlib.pyplot.subplots.html#matplotlib.pyplot.subplots" title="View documentation for matplotlib.pyplot.subplots"><span class="n">plt</span><span class="o">.</span><span class="n">subplots</span></a><span class="p">(</span><a href="https://docs.python.org/3/library/functions.html#int" title="View documentation for builtins.int"><span class="n">nrows</span></a><span class="o">=</span><a href="https://docs.python.org/3/library/functions.html#int" title="View documentation for builtins.int"><span class="n">nrows</span></a><span class="p">)</span>
<a href="../../api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure" title="View documentation for matplotlib.figure.Figure"><span class="n">fig</span></a><span class="o">.</span><span class="n">subplots_adjust</span><span class="p">(</span><span class="n">top</span><span class="o">=</span><span class="mf">0.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>
<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">axes</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><a href="https://docs.python.org/3/library/stdtypes.html#str" title="View documentation for builtins.str"><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="k">for</span> <a href="../../api/_as_gen/matplotlib.axes.SubplotBase.html#matplotlib.axes.SubplotBase" title="View documentation for matplotlib.axes.SubplotBase"><span class="n">ax</span></a><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://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">axes</span></a><span class="p">,</span> <a href="https://docs.python.org/3/library/stdtypes.html#list" title="View documentation for builtins.list"><span class="n">cmap_list</span></a><span class="p">):</span>
<a href="../../api/_as_gen/matplotlib.axes.SubplotBase.html#matplotlib.axes.SubplotBase" title="View documentation for matplotlib.axes.SubplotBase"><span class="n">ax</span></a><span class="o">.</span><span class="n">imshow</span><span class="p">(</span><a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><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="View documentation for builtins.str"><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">pos</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><a href="../../api/_as_gen/matplotlib.axes.SubplotBase.html#matplotlib.axes.SubplotBase" title="View documentation for matplotlib.axes.SubplotBase"><span class="n">ax</span></a><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/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure" title="View documentation for matplotlib.figure.Figure"><span class="n">fig</span></a><span class="o">.</span><span class="n">text</span><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> <a href="../../api/_as_gen/matplotlib.axes.SubplotBase.html#matplotlib.axes.SubplotBase" title="View documentation for matplotlib.axes.SubplotBase"><span class="n">ax</span></a> <span class="ow">in</span> <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">axes</span></a><span class="p">:</span>
<a href="../../api/_as_gen/matplotlib.axes.SubplotBase.html#matplotlib.axes.SubplotBase" title="View documentation for matplotlib.axes.SubplotBase"><span class="n">ax</span></a><span class="o">.</span><span class="n">set_axis_off</span><span class="p">()</span>
<span class="k">for</span> <a href="https://docs.python.org/3/library/stdtypes.html#str" title="View documentation for builtins.str"><span class="n">cmap_category</span></a><span class="p">,</span> <a href="https://docs.python.org/3/library/stdtypes.html#list" title="View documentation for builtins.list"><span class="n">cmap_list</span></a> <span class="ow">in</span> <a href="https://docs.python.org/3/library/collections.html#collections.OrderedDict" title="View documentation for collections.OrderedDict"><span class="n">cmaps</span></a><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<a href="https://docs.python.org/3/library/functions.html#object" title="View documentation for builtins.object"><span class="n">plot_color_gradients</span></a><span class="p">(</span><a href="https://docs.python.org/3/library/stdtypes.html#str" title="View documentation for builtins.str"><span class="n">cmap_category</span></a><span class="p">,</span> <a href="https://docs.python.org/3/library/stdtypes.html#list" title="View documentation for builtins.list"><span class="n">cmap_list</span></a><span class="p">,</span> <a href="https://docs.python.org/3/library/functions.html#int" title="View documentation for builtins.int"><span class="n">nrows</span></a><span class="p">)</span>
<a href="../../api/_as_gen/matplotlib.pyplot.show.html#matplotlib.pyplot.show" title="View documentation for matplotlib.pyplot.show"><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 alt="../../_images/sphx_glr_colormaps_001.png" class="sphx-glr-multi-img first" src="../../_images/sphx_glr_colormaps_001.png" />
</li>
<li><img alt="../../_images/sphx_glr_colormaps_002.png" class="sphx-glr-multi-img first" src="../../_images/sphx_glr_colormaps_002.png" />
</li>
<li><img alt="../../_images/sphx_glr_colormaps_003.png" class="sphx-glr-multi-img first" src="../../_images/sphx_glr_colormaps_003.png" />
</li>
<li><img alt="../../_images/sphx_glr_colormaps_004.png" class="sphx-glr-multi-img first" src="../../_images/sphx_glr_colormaps_004.png" />
</li>
<li><img alt="../../_images/sphx_glr_colormaps_005.png" class="sphx-glr-multi-img first" src="../../_images/sphx_glr_colormaps_005.png" />
</li>
<li><img alt="../../_images/sphx_glr_colormaps_006.png" class="sphx-glr-multi-img first" src="../../_images/sphx_glr_colormaps_006.png" />
</li>
<li><img alt="../../_images/sphx_glr_colormaps_007.png" class="sphx-glr-multi-img first" src="../../_images/sphx_glr_colormaps_007.png" />
</li>
</ul>
</div>
</div>
<div class="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="id11"><span>[list-colormaps]</span></a>).</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">mpl</span><span class="o">.</span><span class="n">rcParams</span><span class="o">.</span><span class="n">update</span><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="View documentation for builtins.dict"><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="View documentation for builtins.dict"><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://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">x</span></a> <span class="o">=</span> <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.linspace.html#numpy.linspace" title="View documentation for numpy.linspace"><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="View documentation for builtins.str"><span class="n">cmap_category</span></a><span class="p">,</span> <a href="https://docs.python.org/3/library/stdtypes.html#list" title="View documentation for builtins.list"><span class="n">cmap_list</span></a> <span class="ow">in</span> <a href="https://docs.python.org/3/library/collections.html#collections.OrderedDict" title="View documentation for collections.OrderedDict"><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="View documentation for builtins.int"><span class="n">dsub</span></a> <span class="o">=</span> <a href="https://docs.python.org/3/library/stdtypes.html#dict.get" title="View documentation for builtins.dict.get"><span class="n">_DSUBS</span><span class="o">.</span><span class="n">get</span></a><span class="p">(</span><a href="https://docs.python.org/3/library/stdtypes.html#str" title="View documentation for builtins.str"><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="View documentation for builtins.int"><span class="n">nsubplots</span></a> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ceil.html#numpy.ceil" title="View documentation for numpy.ceil"><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="View documentation for builtins.list"><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="View documentation for builtins.int"><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/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure" title="View documentation for matplotlib.figure.Figure"><span class="n">fig</span></a><span class="p">,</span> <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">axes</span></a> <span class="o">=</span> <a href="../../api/_as_gen/matplotlib.pyplot.subplots.html#matplotlib.pyplot.subplots" title="View documentation for matplotlib.pyplot.subplots"><span class="n">plt</span><span class="o">.</span><span class="n">subplots</span></a><span class="p">(</span><a href="https://docs.python.org/3/library/functions.html#int" title="View documentation for builtins.int"><span class="n">nrows</span></a><span class="o">=</span><a href="https://docs.python.org/3/library/functions.html#int" title="View documentation for builtins.int"><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="View documentation for builtins.int"><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="View documentation for builtins.int"><span class="n">i</span></a><span class="p">,</span> <a href="../../api/_as_gen/matplotlib.axes.SubplotBase.html#matplotlib.axes.SubplotBase" title="View documentation for matplotlib.axes.SubplotBase"><span class="n">ax</span></a> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.flat.html#numpy.ndarray.flat" title="View documentation for numpy.ndarray.flat"><span class="n">axes</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="View documentation for builtins.list"><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="View documentation for builtins.int"><span class="n">j</span></a><span class="p">,</span> <a href="https://docs.python.org/3/library/stdtypes.html#str" title="View documentation for builtins.str"><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="View documentation for builtins.list"><span class="n">cmap_list</span></a><span class="p">[</span><a href="https://docs.python.org/3/library/functions.html#int" title="View documentation for builtins.int"><span class="n">i</span></a><span class="o">*</span><a href="https://docs.python.org/3/library/functions.html#int" title="View documentation for builtins.int"><span class="n">dsub</span></a><span class="p">:(</span><a href="https://docs.python.org/3/library/functions.html#int" title="View documentation for builtins.int"><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="View documentation for builtins.int"><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://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">rgb</span></a> <span class="o">=</span> <a href="../../api/cm_api.html#matplotlib.cm.get_cmap" title="View documentation for matplotlib.cm.get_cmap"><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="View documentation for builtins.str"><span class="n">cmap</span></a><span class="p">)(</span><a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">x</span></a><span class="p">)[</span><a href="https://docs.scipy.org/doc/numpy/reference/constants.html#numpy.newaxis" title="View documentation for numpy.newaxis"><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://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><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://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><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"># http://stackoverflow.com/questions/8202605/</span>
<span class="k">if</span> <a href="https://docs.python.org/3/library/stdtypes.html#str" title="View documentation for builtins.str"><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://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">y_</span></a> <span class="o">=</span> <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><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://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">c_</span></a> <span class="o">=</span> <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><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://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">y_</span></a> <span class="o">=</span> <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><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://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">c_</span></a> <span class="o">=</span> <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">x</span></a>
<a href="https://docs.python.org/3/library/functions.html#float" title="View documentation for builtins.float"><span class="n">dc</span></a> <span class="o">=</span> <a href="https://docs.python.org/3/library/stdtypes.html#dict.get" title="View documentation for builtins.dict.get"><span class="n">_DC</span><span class="o">.</span><span class="n">get</span></a><span class="p">(</span><a href="https://docs.python.org/3/library/stdtypes.html#str" title="View documentation for builtins.str"><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.SubplotBase.html#matplotlib.axes.SubplotBase" title="View documentation for matplotlib.axes.SubplotBase"><span class="n">ax</span></a><span class="o">.</span><span class="n">scatter</span><span class="p">(</span><a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">x</span></a> <span class="o">+</span> <a href="https://docs.python.org/3/library/functions.html#int" title="View documentation for builtins.int"><span class="n">j</span></a><span class="o">*</span><a href="https://docs.python.org/3/library/functions.html#float" title="View documentation for builtins.float"><span class="n">dc</span></a><span class="p">,</span> <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">y_</span></a><span class="p">,</span> <span class="n">c</span><span class="o">=</span><a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">c_</span></a><span class="p">,</span> <a href="https://docs.python.org/3/library/stdtypes.html#str" title="View documentation for builtins.str"><span class="n">cmap</span></a><span class="o">=</span><a href="https://docs.python.org/3/library/stdtypes.html#str" title="View documentation for builtins.str"><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="View documentation for builtins.str"><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="View documentation for builtins.list"><span class="n">locs</span></a><span class="o">.</span><span class="n">append</span><span class="p">(</span><a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><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="View documentation for builtins.int"><span class="n">j</span></a><span class="o">*</span><a href="https://docs.python.org/3/library/functions.html#float" title="View documentation for builtins.float"><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="View documentation for builtins.str"><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="View documentation for builtins.list"><span class="n">locs</span></a><span class="o">.</span><span class="n">append</span><span class="p">(</span><a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">x</span></a><span class="p">[</span><span class="nb">int</span><span class="p">(</span><a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.size.html#numpy.ndarray.size" title="View documentation for numpy.ndarray.size"><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="View documentation for builtins.int"><span class="n">j</span></a><span class="o">*</span><a href="https://docs.python.org/3/library/functions.html#float" title="View documentation for builtins.float"><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.SubplotBase.html#matplotlib.axes.SubplotBase" title="View documentation for matplotlib.axes.SubplotBase"><span class="n">ax</span></a><span class="o">.</span><span class="n">set_xlim</span><span class="p">(</span><a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">axes</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.SubplotBase.html#matplotlib.axes.SubplotBase" title="View documentation for matplotlib.axes.SubplotBase"><span class="n">ax</span></a><span class="o">.</span><span class="n">set_ylim</span><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.axes.SubplotBase.html#matplotlib.axes.SubplotBase" title="View documentation for matplotlib.axes.SubplotBase"><span class="n">ax</span></a><span class="o">.</span><span class="n">xaxis</span><span class="o">.</span><span class="n">set_ticks_position</span><span class="p">(</span><span class="s1">'top'</span><span class="p">)</span>
<a href="../../api/ticker_api.html#matplotlib.ticker.FixedLocator" title="View documentation for matplotlib.ticker.FixedLocator"><span class="n">ticker</span></a> <span class="o">=</span> <a href="../../api/ticker_api.html#matplotlib.ticker.FixedLocator" title="View documentation for matplotlib.ticker.FixedLocator"><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="View documentation for builtins.list"><span class="n">locs</span></a><span class="p">)</span>
<a href="../../api/_as_gen/matplotlib.axes.SubplotBase.html#matplotlib.axes.SubplotBase" title="View documentation for matplotlib.axes.SubplotBase"><span class="n">ax</span></a><span class="o">.</span><span class="n">xaxis</span><span class="o">.</span><span class="n">set_major_locator</span><span class="p">(</span><a href="../../api/ticker_api.html#matplotlib.ticker.FixedLocator" title="View documentation for matplotlib.ticker.FixedLocator"><span class="n">ticker</span></a><span class="p">)</span>
<a href="../../api/ticker_api.html#matplotlib.ticker.FixedFormatter" title="View documentation for matplotlib.ticker.FixedFormatter"><span class="n">formatter</span></a> <span class="o">=</span> <a href="../../api/ticker_api.html#matplotlib.ticker.FixedFormatter" title="View documentation for matplotlib.ticker.FixedFormatter"><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="View documentation for builtins.list"><span class="n">cmap_list</span></a><span class="p">[</span><a href="https://docs.python.org/3/library/functions.html#int" title="View documentation for builtins.int"><span class="n">i</span></a><span class="o">*</span><a href="https://docs.python.org/3/library/functions.html#int" title="View documentation for builtins.int"><span class="n">dsub</span></a><span class="p">:(</span><a href="https://docs.python.org/3/library/functions.html#int" title="View documentation for builtins.int"><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="View documentation for builtins.int"><span class="n">dsub</span></a><span class="p">])</span>
<a href="../../api/_as_gen/matplotlib.axes.SubplotBase.html#matplotlib.axes.SubplotBase" title="View documentation for matplotlib.axes.SubplotBase"><span class="n">ax</span></a><span class="o">.</span><span class="n">xaxis</span><span class="o">.</span><span class="n">set_major_formatter</span><span class="p">(</span><a href="../../api/ticker_api.html#matplotlib.ticker.FixedFormatter" title="View documentation for matplotlib.ticker.FixedFormatter"><span class="n">formatter</span></a><span class="p">)</span>
<a href="../../api/_as_gen/matplotlib.axes.SubplotBase.html#matplotlib.axes.SubplotBase" title="View documentation for matplotlib.axes.SubplotBase"><span class="n">ax</span></a><span class="o">.</span><span class="n">xaxis</span><span class="o">.</span><span class="n">set_tick_params</span><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.SubplotBase.html#matplotlib.axes.SubplotBase" title="View documentation for matplotlib.axes.SubplotBase"><span class="n">ax</span></a><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><a href="https://docs.python.org/3/library/stdtypes.html#str" title="View documentation for builtins.str"><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/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure" title="View documentation for matplotlib.figure.Figure"><span class="n">fig</span></a><span class="o">.</span><span class="n">text</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="mf">0.55</span><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>
<span class="n">transform</span><span class="o">=</span><a href="../../api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure" title="View documentation for matplotlib.figure.Figure"><span class="n">fig</span></a><span class="o">.</span><span class="n">transFigure</span><span class="p">,</span> <span class="n">rotation</span><span class="o">=</span><span class="mi">90</span><span class="p">)</span>
<a href="../../api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure" title="View documentation for matplotlib.figure.Figure"><span class="n">fig</span></a><span class="o">.</span><span class="n">tight_layout</span><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="View documentation for matplotlib.pyplot.show"><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 alt="../../_images/sphx_glr_colormaps_008.png" class="sphx-glr-multi-img first" src="../../_images/sphx_glr_colormaps_008.png" />
</li>
<li><img alt="../../_images/sphx_glr_colormaps_009.png" class="sphx-glr-multi-img first" src="../../_images/sphx_glr_colormaps_009.png" />
</li>
<li><img alt="../../_images/sphx_glr_colormaps_010.png" class="sphx-glr-multi-img first" src="../../_images/sphx_glr_colormaps_010.png" />
</li>
<li><img alt="../../_images/sphx_glr_colormaps_011.png" class="sphx-glr-multi-img first" src="../../_images/sphx_glr_colormaps_011.png" />
</li>
<li><img alt="../../_images/sphx_glr_colormaps_012.png" class="sphx-glr-multi-img first" src="../../_images/sphx_glr_colormaps_012.png" />
</li>
<li><img alt="../../_images/sphx_glr_colormaps_013.png" class="sphx-glr-multi-img first" src="../../_images/sphx_glr_colormaps_013.png" />
</li>
<li><img alt="../../_images/sphx_glr_colormaps_014.png" class="sphx-glr-multi-img first" src="../../_images/sphx_glr_colormaps_014.png" />
</li>
</ul>
</div>
<div class="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="id12"><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, and jet, change from darker to lighter and back to darker gray
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><span class="n">mpl</span><span class="o">.</span><span class="n">rcParams</span><span class="o">.</span><span class="n">update</span><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://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">x</span></a> <span class="o">=</span> <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.linspace.html#numpy.linspace" title="View documentation for numpy.linspace"><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://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">gradient</span></a> <span class="o">=</span> <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.linspace.html#numpy.linspace" title="View documentation for numpy.linspace"><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://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">gradient</span></a> <span class="o">=</span> <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.vstack.html#numpy.vstack" title="View documentation for numpy.vstack"><span class="n">np</span><span class="o">.</span><span class="n">vstack</span></a><span class="p">((</span><a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">gradient</span></a><span class="p">,</span> <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><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="View documentation for builtins.str"><span class="n">cmap_category</span></a><span class="p">,</span> <a href="https://docs.python.org/3/library/stdtypes.html#list" title="View documentation for builtins.list"><span class="n">cmap_list</span></a><span class="p">):</span>
<a href="../../api/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure" title="View documentation for matplotlib.figure.Figure"><span class="n">fig</span></a><span class="p">,</span> <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">axes</span></a> <span class="o">=</span> <a href="../../api/_as_gen/matplotlib.pyplot.subplots.html#matplotlib.pyplot.subplots" title="View documentation for matplotlib.pyplot.subplots"><span class="n">plt</span><span class="o">.</span><span class="n">subplots</span></a><span class="p">(</span><a href="https://docs.python.org/3/library/functions.html#int" title="View documentation for builtins.int"><span class="n">nrows</span></a><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="View documentation for builtins.list"><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/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure" title="View documentation for matplotlib.figure.Figure"><span class="n">fig</span></a><span class="o">.</span><span class="n">subplots_adjust</span><span class="p">(</span><span class="n">top</span><span class="o">=</span><span class="mf">0.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/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure" title="View documentation for matplotlib.figure.Figure"><span class="n">fig</span></a><span class="o">.</span><span class="n">suptitle</span><span class="p">(</span><a href="https://docs.python.org/3/library/stdtypes.html#str" title="View documentation for builtins.str"><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://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><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> <a href="../../api/_as_gen/matplotlib.axes.SubplotBase.html#matplotlib.axes.SubplotBase" title="View documentation for matplotlib.axes.SubplotBase"><span class="n">ax</span></a><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://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">axes</span></a><span class="p">,</span> <a href="https://docs.python.org/3/library/stdtypes.html#list" title="View documentation for builtins.list"><span class="n">cmap_list</span></a><span class="p">):</span>
<span class="c1"># Get RGB values for colormap.</span>
<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">rgb</span></a> <span class="o">=</span> <a href="../../api/cm_api.html#matplotlib.cm.get_cmap" title="View documentation for matplotlib.cm.get_cmap"><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://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">x</span></a><span class="p">)[</span><a href="https://docs.scipy.org/doc/numpy/reference/constants.html#numpy.newaxis" title="View documentation for numpy.newaxis"><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://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><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://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><span class="n">rgb</span></a><span class="p">)</span>
<span class="n">L</span> <span class="o">=</span> <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><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> <span class="n">np</span><span class="o">.</span><span class="n">float32</span><span class="p">(</span><a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.vstack.html#numpy.vstack" title="View documentation for numpy.vstack"><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>
<a href="../../api/_as_gen/matplotlib.axes.SubplotBase.html#matplotlib.axes.SubplotBase" title="View documentation for matplotlib.axes.SubplotBase"><span class="n">ax</span></a><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://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html#numpy.ndarray" title="View documentation for numpy.ndarray"><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="View documentation for builtins.str"><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.SubplotBase.html#matplotlib.axes.SubplotBase" title="View documentation for matplotlib.axes.SubplotBase"><span class="n">ax</span></a><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="View documentation for builtins.str"><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><a href="../../api/_as_gen/matplotlib.axes.SubplotBase.html#matplotlib.axes.SubplotBase" title="View documentation for matplotlib.axes.SubplotBase"><span class="n">ax</span></a><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/_as_gen/matplotlib.figure.Figure.html#matplotlib.figure.Figure" title="View documentation for matplotlib.figure.Figure"><span class="n">fig</span></a><span class="o">.</span><span class="n">text</span><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> <a href="../../api/_as_gen/matplotlib.axes.SubplotBase.html#matplotlib.axes.SubplotBase" title="View documentation for matplotlib.axes.SubplotBase"><span class="n">ax</span></a> <span class="ow">in</span> <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.flat.html#numpy.ndarray.flat" title="View documentation for numpy.ndarray.flat"><span class="n">axes</span><span class="o">.</span><span class="n">flat</span></a><span class="p">:</span>
<a href="../../api/_as_gen/matplotlib.axes.SubplotBase.html#matplotlib.axes.SubplotBase" title="View documentation for matplotlib.axes.SubplotBase"><span class="n">ax</span></a><span class="o">.</span><span class="n">set_axis_off</span><span class="p">()</span>
<a href="../../api/_as_gen/matplotlib.pyplot.show.html#matplotlib.pyplot.show" title="View documentation for matplotlib.pyplot.show"><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="View documentation for builtins.str"><span class="n">cmap_category</span></a><span class="p">,</span> <a href="https://docs.python.org/3/library/stdtypes.html#list" title="View documentation for builtins.list"><span class="n">cmap_list</span></a> <span class="ow">in</span> <a href="https://docs.python.org/3/library/collections.html#collections.OrderedDict" title="View documentation for collections.OrderedDict"><span class="n">cmaps</span></a><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<a href="https://docs.python.org/3/library/functions.html#object" title="View documentation for builtins.object"><span class="n">plot_color_gradients</span></a><span class="p">(</span><a href="https://docs.python.org/3/library/stdtypes.html#str" title="View documentation for builtins.str"><span class="n">cmap_category</span></a><span class="p">,</span> <a href="https://docs.python.org/3/library/stdtypes.html#list" title="View documentation for builtins.list"><span class="n">cmap_list</span></a><span class="p">)</span>
</pre></div>
</div>
<ul class="sphx-glr-horizontal">
<li><img alt="../../_images/sphx_glr_colormaps_015.png" class="sphx-glr-multi-img first" src="../../_images/sphx_glr_colormaps_015.png" />
</li>
<li><img alt="../../_images/sphx_glr_colormaps_016.png" class="sphx-glr-multi-img first" src="../../_images/sphx_glr_colormaps_016.png" />
</li>
<li><img alt="../../_images/sphx_glr_colormaps_017.png" class="sphx-glr-multi-img first" src="../../_images/sphx_glr_colormaps_017.png" />
</li>
<li><img alt="../../_images/sphx_glr_colormaps_018.png" class="sphx-glr-multi-img first" src="../../_images/sphx_glr_colormaps_018.png" />
</li>
<li><img alt="../../_images/sphx_glr_colormaps_019.png" class="sphx-glr-multi-img first" src="../../_images/sphx_glr_colormaps_019.png" />
</li>
<li><img alt="../../_images/sphx_glr_colormaps_020.png" class="sphx-glr-multi-img first" src="../../_images/sphx_glr_colormaps_020.png" />
</li>
<li><img alt="../../_images/sphx_glr_colormaps_021.png" class="sphx-glr-multi-img first" src="../../_images/sphx_glr_colormaps_021.png" />
</li>
</ul>
</div>
<div class="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="id13"><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>
</div>
<div class="section" id="references">
<h2>References<a class="headerlink" href="#references" title="Permalink to this headline">¶</a></h2>
<table class="docutils citation" frame="void" id="colorcet" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label">[colorcet]</td><td><em>(<a class="fn-backref" href="#id2">1</a>, <a class="fn-backref" href="#id4">2</a>)</em> <a class="reference external" href="https://colorcet.pyviz.org">https://colorcet.pyviz.org</a></td></tr>
</tbody>
</table>
<table class="docutils citation" frame="void" id="ware" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id3">[Ware]</a></td><td><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></td></tr>
</tbody>
</table>
<table class="docutils citation" frame="void" id="moreland" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id6">[Moreland]</a></td><td><a class="reference external" href="http://www.kennethmoreland.com/color-maps/ColorMapsExpanded.pdf">http://www.kennethmoreland.com/color-maps/ColorMapsExpanded.pdf</a></td></tr>
</tbody>
</table>
<table class="docutils citation" frame="void" id="list-colormaps" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id11">[list-colormaps]</a></td><td><a class="reference external" href="https://gist.github.com/endolith/2719900#id7">https://gist.github.com/endolith/2719900#id7</a></td></tr>
</tbody>
</table>
<table class="docutils citation" frame="void" id="mycarta-banding" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id7">[mycarta-banding]</a></td><td><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></td></tr>
</tbody>
</table>
<table class="docutils citation" frame="void" id="mycarta-jet" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label">[mycarta-jet]</td><td><em>(<a class="fn-backref" href="#id9">1</a>, <a class="fn-backref" href="#id10">2</a>)</em> <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></td></tr>
</tbody>
</table>
<table class="docutils citation" frame="void" id="kovesi-colormaps" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id8">[kovesi-colormaps]</a></td><td><a class="reference external" href="https://arxiv.org/abs/1509.03700">https://arxiv.org/abs/1509.03700</a></td></tr>
</tbody>
</table>
<table class="docutils citation" frame="void" id="bw" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id12">[bw]</a></td><td><a class="reference external" href="http://www.tannerhelland.com/3643/grayscale-image-algorithm-vb6/">http://www.tannerhelland.com/3643/grayscale-image-algorithm-vb6/</a></td></tr>
</tbody>
</table>
<table class="docutils citation" frame="void" id="colorblindness" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id13">[colorblindness]</a></td><td><a class="reference external" href="http://www.color-blindness.com/">http://www.color-blindness.com/</a></td></tr>
</tbody>
</table>
<table class="docutils citation" frame="void" id="ibm" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id5">[IBM]</a></td><td><a class="reference external" href="https://doi.org/10.1109/VISUAL.1995.480803">https://doi.org/10.1109/VISUAL.1995.480803</a></td></tr>
</tbody>
</table>
<table class="docutils citation" frame="void" id="palettable" rules="none">
<colgroup><col class="label" /><col /></colgroup>
<tbody valign="top">
<tr><td class="label"><a class="fn-backref" href="#id1">[palettable]</a></td><td><a class="reference external" href="https://jiffyclub.github.io/palettable/">https://jiffyclub.github.io/palettable/</a></td></tr>
</tbody>
</table>
<p class="sphx-glr-timing"><strong>Total running time of the script:</strong> ( 0 minutes 4.606 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 docutils container">
<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></div>
<div class="sphx-glr-download docutils container">
<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></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>
</div>
</div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<footer>
<div class="footer">
© Copyright 2002 - 2012 John Hunter, Darren Dale, Eric Firing, Michael Droettboom and the Matplotlib development team; 2012 - 2018 The Matplotlib development team.
<br />
Last updated on Mar 04, 2020.
Created using
<a href="http://sphinx-doc.org/">Sphinx</a> 2.4.3.
Doc version v3.2.0-3-gea62ccde8.
</div>
</footer>
</body>
</html>