-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathcolors_api.html
More file actions
296 lines (272 loc) · 22.1 KB
/
colors_api.html
File metadata and controls
296 lines (272 loc) · 22.1 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
<!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="Content-Type" content="text/html; charset=utf-8" />
<title>colors — Matplotlib 2.2.5 documentation</title>
<link rel="stylesheet" href="../_static/mpl.css"
type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css"
type="text/css" />
<link rel="stylesheet" href="../_static/graphviz.css" type="text/css" />
<link rel="stylesheet" href="../_static/gallery.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '2.2.5',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="../_static/language_data.js"></script>
<script type="text/javascript" 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 2.2.5 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="top" title="Matplotlib 2.2.5 documentation" href="../index.html" />
<link rel="up" title="The Matplotlib API" href="index.html" />
<link rel="next" title="matplotlib.colors.BoundaryNorm" href="_as_gen/matplotlib.colors.BoundaryNorm.html" />
<link rel="prev" title="colorbar" href="colorbar_api.html" />
<link rel="canonical" href="https://matplotlib.org/stable/api/colors_api.html" />
<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 (v2.2.5). For the latest version see <a href="https://matplotlib.org/stable/api/colors_api.html">https://matplotlib.org/stable/api/colors_api.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 2.2.5</span></div>
<img src="../_static/logo2.png" 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>
<div class="related">
<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="_as_gen/matplotlib.colors.BoundaryNorm.html" title="matplotlib.colors.BoundaryNorm"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="colorbar_api.html" title="colorbar"
accesskey="P">previous</a> |</li>
<li><a href="../index.html">home</a>| </li>
<li><a href="../gallery/index.html">examples</a>| </li>
<li><a href="../tutorials/index.html">tutorials</a>| </li>
<li><a href="pyplot_summary.html">pyplot</a>| </li>
<li><a href="../contents.html">docs</a> »</li>
<li><a href="index.html" accesskey="U">The Matplotlib API</a> »</li>
</ul>
</div>
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">colors</a><ul>
<li><a class="reference internal" href="#module-matplotlib.colors"><code class="docutils literal notranslate"><span class="pre">matplotlib.colors</span></code></a><ul>
<li><a class="reference internal" href="#classes">Classes</a></li>
<li><a class="reference internal" href="#functions">Functions</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="../contents.html">Documentation overview</a><ul>
<li><a href="index.html">The Matplotlib API</a><ul>
<li>Previous: <a href="colorbar_api.html" title="previous chapter">colorbar</a></li>
<li>Next: <a href="_as_gen/matplotlib.colors.BoundaryNorm.html" title="next chapter">matplotlib.colors.BoundaryNorm</a></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/api/colors_api.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">
<div class="section" id="colors">
<h1>colors<a class="headerlink" href="#colors" title="Permalink to this headline">¶</a></h1>
<p>For a visual representation of the Matplotlib colormaps, see:</p>
<ul class="simple">
<li>The <a class="reference internal" href="../gallery/index.html#color-examples"><span class="std std-ref">Color</span></a> examples for examples of controlling color with
Matplotlib.</li>
<li>The <a class="reference internal" href="../tutorials/index.html#tutorials-colors"><span class="std std-ref">Colors</span></a> tutorial for an in-depth guide on controlling
color.</li>
</ul>
<div class="section" id="module-matplotlib.colors">
<span id="matplotlib-colors"></span><h2><a class="reference internal" href="#module-matplotlib.colors" title="matplotlib.colors"><code class="xref py py-mod docutils literal notranslate"><span class="pre">matplotlib.colors</span></code></a><a class="headerlink" href="#module-matplotlib.colors" title="Permalink to this headline">¶</a></h2>
<p>A module for converting numbers or color arguments to <em>RGB</em> or <em>RGBA</em></p>
<p><em>RGB</em> and <em>RGBA</em> are sequences of, respectively, 3 or 4 floats in the
range 0-1.</p>
<p>This module includes functions and classes for color specification
conversions, and for mapping numbers to colors in a 1-D array of colors called
a colormap. Colormapping typically involves two steps: a data array is first
mapped onto the range 0-1 using an instance of <a class="reference internal" href="_as_gen/matplotlib.colors.Normalize.html#matplotlib.colors.Normalize" title="matplotlib.colors.Normalize"><code class="xref py py-class docutils literal notranslate"><span class="pre">Normalize</span></code></a> or of a
subclass; then this number in the 0-1 range is mapped to a color using an
instance of a subclass of <a class="reference internal" href="_as_gen/matplotlib.colors.Colormap.html#matplotlib.colors.Colormap" title="matplotlib.colors.Colormap"><code class="xref py py-class docutils literal notranslate"><span class="pre">Colormap</span></code></a>. Two are provided here:
<a class="reference internal" href="_as_gen/matplotlib.colors.LinearSegmentedColormap.html#matplotlib.colors.LinearSegmentedColormap" title="matplotlib.colors.LinearSegmentedColormap"><code class="xref py py-class docutils literal notranslate"><span class="pre">LinearSegmentedColormap</span></code></a>, which is used to generate all the built-in
colormap instances, but is also useful for making custom colormaps, and
<a class="reference internal" href="_as_gen/matplotlib.colors.ListedColormap.html#matplotlib.colors.ListedColormap" title="matplotlib.colors.ListedColormap"><code class="xref py py-class docutils literal notranslate"><span class="pre">ListedColormap</span></code></a>, which is used for generating a custom colormap from a
list of color specifications.</p>
<p>The module also provides functions for checking whether an object can be
interpreted as a color (<a class="reference internal" href="_as_gen/matplotlib.colors.is_color_like.html#matplotlib.colors.is_color_like" title="matplotlib.colors.is_color_like"><code class="xref py py-func docutils literal notranslate"><span class="pre">is_color_like()</span></code></a>), for converting such an object
to an RGBA tuple (<a class="reference internal" href="_as_gen/matplotlib.colors.to_rgba.html#matplotlib.colors.to_rgba" title="matplotlib.colors.to_rgba"><code class="xref py py-func docutils literal notranslate"><span class="pre">to_rgba()</span></code></a>) or to an HTML-like hex string in the
<code class="xref py py-obj docutils literal notranslate"><span class="pre">#rrggbb</span></code> format (<a class="reference internal" href="_as_gen/matplotlib.colors.to_hex.html#matplotlib.colors.to_hex" title="matplotlib.colors.to_hex"><code class="xref py py-func docutils literal notranslate"><span class="pre">to_hex()</span></code></a>), and a sequence of colors to an <code class="xref py py-obj docutils literal notranslate"><span class="pre">(n,</span> <span class="pre">4)</span></code>
RGBA array (<a class="reference internal" href="_as_gen/matplotlib.colors.to_rgba_array.html#matplotlib.colors.to_rgba_array" title="matplotlib.colors.to_rgba_array"><code class="xref py py-func docutils literal notranslate"><span class="pre">to_rgba_array()</span></code></a>). Caching is used for efficiency.</p>
<p>Matplotlib recognizes the following formats to specify a color:</p>
<ul class="simple">
<li>an RGB or RGBA tuple of float values in <code class="docutils literal notranslate"><span class="pre">[0,</span> <span class="pre">1]</span></code> (e.g., <code class="docutils literal notranslate"><span class="pre">(0.1,</span> <span class="pre">0.2,</span> <span class="pre">0.5)</span></code>
or <code class="docutils literal notranslate"><span class="pre">(0.1,</span> <span class="pre">0.2,</span> <span class="pre">0.5,</span> <span class="pre">0.3)</span></code>);</li>
<li>a hex RGB or RGBA string (e.g., <code class="docutils literal notranslate"><span class="pre">'#0F0F0F'</span></code> or <code class="docutils literal notranslate"><span class="pre">'#0F0F0F0F'</span></code>);</li>
<li>a string representation of a float value in <code class="docutils literal notranslate"><span class="pre">[0,</span> <span class="pre">1]</span></code> inclusive for gray
level (e.g., <code class="docutils literal notranslate"><span class="pre">'0.5'</span></code>);</li>
<li>one of <code class="docutils literal notranslate"><span class="pre">{'b',</span> <span class="pre">'g',</span> <span class="pre">'r',</span> <span class="pre">'c',</span> <span class="pre">'m',</span> <span class="pre">'y',</span> <span class="pre">'k',</span> <span class="pre">'w'}</span></code>;</li>
<li>a X11/CSS4 color name;</li>
<li>a name from the <a class="reference external" href="https://xkcd.com/color/rgb/">xkcd color survey</a>;
prefixed with <code class="docutils literal notranslate"><span class="pre">'xkcd:'</span></code> (e.g., <code class="docutils literal notranslate"><span class="pre">'xkcd:sky</span> <span class="pre">blue'</span></code>);</li>
<li>one of <code class="docutils literal notranslate"><span class="pre">{'tab:blue',</span> <span class="pre">'tab:orange',</span> <span class="pre">'tab:green',</span>
<span class="pre">'tab:red',</span> <span class="pre">'tab:purple',</span> <span class="pre">'tab:brown',</span> <span class="pre">'tab:pink',</span>
<span class="pre">'tab:gray',</span> <span class="pre">'tab:olive',</span> <span class="pre">'tab:cyan'}</span></code> which are the Tableau Colors from the
'T10' categorical palette (which is the default color cycle);</li>
<li>a "CN" color spec, i.e. <code class="xref py py-obj docutils literal notranslate"><span class="pre">'C'</span></code> followed by a single digit, which is an index
into the default property cycle (<code class="docutils literal notranslate"><span class="pre">matplotlib.rcParams['axes.prop_cycle']</span></code>);
the indexing occurs at artist creation time and defaults to black if the
cycle does not include color.</li>
</ul>
<p>All string specifications of color, other than "CN", are case-insensitive.</p>
<div class="section" id="classes">
<h3>Classes<a class="headerlink" href="#classes" title="Permalink to this headline">¶</a></h3>
<table border="1" class="longtable docutils">
<colgroup>
<col width="10%" />
<col width="90%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><a class="reference internal" href="_as_gen/matplotlib.colors.BoundaryNorm.html#matplotlib.colors.BoundaryNorm" title="matplotlib.colors.BoundaryNorm"><code class="xref py py-obj docutils literal notranslate"><span class="pre">BoundaryNorm</span></code></a>(boundaries, ncolors[, clip])</td>
<td>Generate a colormap index based on discrete intervals.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="_as_gen/matplotlib.colors.Colormap.html#matplotlib.colors.Colormap" title="matplotlib.colors.Colormap"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Colormap</span></code></a>(name[, N])</td>
<td>Baseclass for all scalar to RGBA mappings.</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="_as_gen/matplotlib.colors.LightSource.html#matplotlib.colors.LightSource" title="matplotlib.colors.LightSource"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LightSource</span></code></a>([azdeg, altdeg, hsv_min_val, ...])</td>
<td>Create a light source coming from the specified azimuth and elevation.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="_as_gen/matplotlib.colors.LinearSegmentedColormap.html#matplotlib.colors.LinearSegmentedColormap" title="matplotlib.colors.LinearSegmentedColormap"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LinearSegmentedColormap</span></code></a>(name, segmentdata[, ...])</td>
<td>Colormap objects based on lookup tables using linear segments.</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="_as_gen/matplotlib.colors.ListedColormap.html#matplotlib.colors.ListedColormap" title="matplotlib.colors.ListedColormap"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ListedColormap</span></code></a>(colors[, name, N])</td>
<td>Colormap object generated from a list of colors.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="_as_gen/matplotlib.colors.LogNorm.html#matplotlib.colors.LogNorm" title="matplotlib.colors.LogNorm"><code class="xref py py-obj docutils literal notranslate"><span class="pre">LogNorm</span></code></a>([vmin, vmax, clip])</td>
<td>Normalize a given value to the 0-1 range on a log scale</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="_as_gen/matplotlib.colors.NoNorm.html#matplotlib.colors.NoNorm" title="matplotlib.colors.NoNorm"><code class="xref py py-obj docutils literal notranslate"><span class="pre">NoNorm</span></code></a>([vmin, vmax, clip])</td>
<td>Dummy replacement for Normalize, for the case where we want to use indices directly in a <a class="reference internal" href="cm_api.html#matplotlib.cm.ScalarMappable" title="matplotlib.cm.ScalarMappable"><code class="xref py py-class docutils literal notranslate"><span class="pre">ScalarMappable</span></code></a> .</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="_as_gen/matplotlib.colors.Normalize.html#matplotlib.colors.Normalize" title="matplotlib.colors.Normalize"><code class="xref py py-obj docutils literal notranslate"><span class="pre">Normalize</span></code></a>([vmin, vmax, clip])</td>
<td>A class which, when called, can normalize data into the <code class="docutils literal notranslate"><span class="pre">[0.0,</span> <span class="pre">1.0]</span></code> interval.</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="_as_gen/matplotlib.colors.PowerNorm.html#matplotlib.colors.PowerNorm" title="matplotlib.colors.PowerNorm"><code class="xref py py-obj docutils literal notranslate"><span class="pre">PowerNorm</span></code></a>(gamma[, vmin, vmax, clip])</td>
<td>Normalize a given value to the <code class="docutils literal notranslate"><span class="pre">[0,</span> <span class="pre">1]</span></code> interval with a power-law scaling.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="_as_gen/matplotlib.colors.SymLogNorm.html#matplotlib.colors.SymLogNorm" title="matplotlib.colors.SymLogNorm"><code class="xref py py-obj docutils literal notranslate"><span class="pre">SymLogNorm</span></code></a>(linthresh[, linscale, vmin, ...])</td>
<td>The symmetrical logarithmic scale is logarithmic in both the positive and negative directions from the origin.</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="functions">
<h3>Functions<a class="headerlink" href="#functions" title="Permalink to this headline">¶</a></h3>
<table border="1" class="longtable docutils">
<colgroup>
<col width="10%" />
<col width="90%" />
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><a class="reference internal" href="_as_gen/matplotlib.colors.from_levels_and_colors.html#matplotlib.colors.from_levels_and_colors" title="matplotlib.colors.from_levels_and_colors"><code class="xref py py-obj docutils literal notranslate"><span class="pre">from_levels_and_colors</span></code></a>(levels, colors[, extend])</td>
<td>A helper routine to generate a cmap and a norm instance which behave similar to contourf's levels and colors arguments.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="_as_gen/matplotlib.colors.hsv_to_rgb.html#matplotlib.colors.hsv_to_rgb" title="matplotlib.colors.hsv_to_rgb"><code class="xref py py-obj docutils literal notranslate"><span class="pre">hsv_to_rgb</span></code></a>(hsv)</td>
<td>convert hsv values in a numpy array to rgb values all values assumed to be in range [0, 1]</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="_as_gen/matplotlib.colors.rgb_to_hsv.html#matplotlib.colors.rgb_to_hsv" title="matplotlib.colors.rgb_to_hsv"><code class="xref py py-obj docutils literal notranslate"><span class="pre">rgb_to_hsv</span></code></a>(arr)</td>
<td>convert float rgb values (in the range [0, 1]), in a numpy array to hsv values.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="_as_gen/matplotlib.colors.to_hex.html#matplotlib.colors.to_hex" title="matplotlib.colors.to_hex"><code class="xref py py-obj docutils literal notranslate"><span class="pre">to_hex</span></code></a>(c[, keep_alpha])</td>
<td>Convert <em>c</em> to a hex color.</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="_as_gen/matplotlib.colors.to_rgb.html#matplotlib.colors.to_rgb" title="matplotlib.colors.to_rgb"><code class="xref py py-obj docutils literal notranslate"><span class="pre">to_rgb</span></code></a>(c)</td>
<td>Convert <em>c</em> to an RGB color, silently dropping the alpha channel.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="_as_gen/matplotlib.colors.to_rgba.html#matplotlib.colors.to_rgba" title="matplotlib.colors.to_rgba"><code class="xref py py-obj docutils literal notranslate"><span class="pre">to_rgba</span></code></a>(c[, alpha])</td>
<td>Convert <em>c</em> to an RGBA color.</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="_as_gen/matplotlib.colors.to_rgba_array.html#matplotlib.colors.to_rgba_array" title="matplotlib.colors.to_rgba_array"><code class="xref py py-obj docutils literal notranslate"><span class="pre">to_rgba_array</span></code></a>(c[, alpha])</td>
<td>Convert <em>c</em> to a (n, 4) array of RGBA colors.</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="_as_gen/matplotlib.colors.is_color_like.html#matplotlib.colors.is_color_like" title="matplotlib.colors.is_color_like"><code class="xref py py-obj docutils literal notranslate"><span class="pre">is_color_like</span></code></a>(c)</td>
<td>Return whether <em>c</em> can be interpreted as an RGB(A) color.</td>
</tr>
<tr class="row-odd"><td><a class="reference internal" href="_as_gen/matplotlib.colors.makeMappingArray.html#matplotlib.colors.makeMappingArray" title="matplotlib.colors.makeMappingArray"><code class="xref py py-obj docutils literal notranslate"><span class="pre">makeMappingArray</span></code></a>(N, data[, gamma])</td>
<td>Create an <em>N</em> -element 1-d lookup table</td>
</tr>
<tr class="row-even"><td><a class="reference internal" href="_as_gen/matplotlib.colors.get_named_colors_mapping.html#matplotlib.colors.get_named_colors_mapping" title="matplotlib.colors.get_named_colors_mapping"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_named_colors_mapping</span></code></a>()</td>
<td>Return the global mapping of names to named colors.</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<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 Feb 09, 2020.
Created using
<ahref="http://sphinx-doc.org/">Sphinx</a> 1.8.5.
Doc version v2.2.5-2-ga847ffac5.
</div>
</body>
<footer>
</footer>
</html>