You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.
Dismiss alert
<divid="unreleased-message"> You are reading an old version of the documentation (v3.3.4). For the latest version see <ahref="https://matplotlib.org/stable/tutorials/colors/colormaps.html">https://matplotlib.org/stable/tutorials/colors/colormaps.html</a></div>
<spanid="sphx-glr-tutorials-colors-colormaps-py"></span><h1>Choosing Colormaps in Matplotlib<aclass="headerlink" href="#choosing-colormaps-in-matplotlib" title="Permalink to this headline">¶</a></h1>
<p>Matplotlib has a number of built-in colormaps accessible via
<aclass="reference internal" href="../../api/cm_api.html#matplotlib.cm.get_cmap" title="matplotlib.cm.get_cmap"><codeclass="xref py py-obj docutils literal notranslate"><spanclass="pre">matplotlib.cm.get_cmap</span></code></a>. There are also external libraries like
<aclass="reference internal" href="#palettable" id="id1"><span>[palettable]</span></a> and <aclass="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
<aclass="reference internal" href="colormap-manipulation.html"><spanclass="doc">Creating Colormaps in Matplotlib</span></a>.</p>
<divclass="section" id="overview">
<h2>Overview<aclass="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>
<ulclass="simple">
<li>Whether representing form or metric data (<aclass="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;
i.e. a colormap in which equal steps in data are perceived as equal
steps in the color space. Researchers have found that the human brain
perceives changes in the lightness parameter as changes in the data
much better than, for example, changes in hue. Therefore, colormaps
which have monotonically increasing lightness through the colormap
will be better interpreted by the viewer. A wonderful example of
perceptually uniform colormaps is <aclass="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,
<spanclass="math notranslate nohighlight">\(L^*\)</span>; red-green, <spanclass="math notranslate nohighlight">\(a^*\)</span>; and yellow-blue, <spanclass="math notranslate nohighlight">\(b^*\)</span>. The lightness
parameter <spanclass="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 <aclass="reference internal" href="#ibm" id="id5"><span>[IBM]</span></a>.</p>
</div>
<divclass="section" id="classes-of-colormaps">
<h2>Classes of colormaps<aclass="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,
<h3>Sequential<aclass="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 <spanclass="math notranslate nohighlight">\(L^*\)</span> values in the colormaps
span from 0 to 100 (binary and the other grayscale), and others start around
<spanclass="math notranslate nohighlight">\(L^*=20\)</span>. Those that have a smaller range of <spanclass="math notranslate nohighlight">\(L^*\)</span> will accordingly
have a smaller perceptual range. Note also that the <spanclass="math notranslate nohighlight">\(L^*\)</span> function varies
amongst the colormaps: some are approximately linear in <spanclass="math notranslate nohighlight">\(L^*\)</span> and others
<h3>Sequential2<aclass="headerlink" href="#sequential2" title="Permalink to this headline">¶</a></h3>
<p>Many of the <spanclass="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 <spanclass="math notranslate nohighlight">\(L^*\)</span> space. Others (afmhot, copper, gist_heat, and hot)
have kinks in the <spanclass="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 <aclass="reference internal" href="#mycarta-banding" id="id7"><span>[mycarta-banding]</span></a> for
<h3>Cyclic<aclass="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. <spanclass="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, <spanclass="math notranslate nohighlight">\(L^*\)</span> will reverse direction, which should be smoothed in
<spanclass="math notranslate nohighlight">\(L^*\)</span> space to reduce artifacts. See <aclass="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 <spanclass="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
<h3>Miscellaneous<aclass="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
<spanclass="math notranslate nohighlight">\(L^*\)</span>. cubehelix was created to vary smoothly in both lightness
and hue, but appears to have a small hump in the green hue area. turbo
was created to display depth and disparity data.</p>
<p>The often-used jet colormap is included in this set of colormaps. We can see
that the <spanclass="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 <aclass="reference internal" href="#mycarta-jet" id="id10"><span>[mycarta-jet]</span></a> and <aclass="reference internal" href="#turbo" id="id11"><span>[turbo]</span></a>.</p>
<h2>Color vision deficiencies<aclass="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>,
<aclass="reference internal" href="#colorblindness" id="id14"><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>
<divclass="section" id="references">
<h2>References<aclass="headerlink" href="#references" title="Permalink to this headline">¶</a></h2>