-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathcolor_demo.html
More file actions
234 lines (206 loc) · 18.6 KB
/
color_demo.html
File metadata and controls
234 lines (206 loc) · 18.6 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
<!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>Color Demo — 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="canonical" href="https://matplotlib.org/stable/gallery/color/color_demo.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/gallery/color/color_demo.html">https://matplotlib.org/stable/gallery/color/color_demo.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><a href="../../index.html">home</a>| </li>
<li><a href="../index.html">examples</a>| </li>
<li><a href="../../tutorials/index.html">tutorials</a>| </li>
<li><a href="../../api/pyplot_summary.html">pyplot</a>| </li>
<li><a href="../../contents.html">docs</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="#">Color Demo</a><ul>
<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>
</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/gallery/color/color_demo.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="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-gallery-color-color-demo-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="color-demo">
<span id="sphx-glr-gallery-color-color-demo-py"></span><h1>Color Demo<a class="headerlink" href="#color-demo" title="Permalink to this headline">¶</a></h1>
<p>Matplotlib gives you 8 ways to specify colors,</p>
<ol class="arabic 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>). RGBA is short for Red, Green, Blue, Alpha;</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>a single letter string, i.e. 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 ("html") color name, e.g. <code class="docutils literal notranslate"><span class="pre">"blue"</span></code>;</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>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>
<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
'tab10' categorical palette (which is the default color cycle);</li>
</ol>
<p>For more information on colors in matplotlib see</p>
<ul class="simple">
<li>the <a class="reference internal" href="../../tutorials/colors/colors.html"><span class="doc">Specifying Colors</span></a> tutorial;</li>
<li>the <a class="reference internal" href="../../api/colors_api.html#module-matplotlib.colors" title="matplotlib.colors"><code class="xref py py-obj docutils literal notranslate"><span class="pre">matplotlib.colors</span></code></a> API;</li>
<li>the <a class="reference internal" href="named_colors.html"><span class="doc">Visualizing named colors</span></a> example.</li>
</ul>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></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">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</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">t</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">2.0</span><span class="p">,</span> <span class="mi">201</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">s</span></a> <span class="o">=</span> <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.sin.html#numpy.sin" title="View documentation for numpy.sin"><span class="n">np</span><span class="o">.</span><span class="n">sin</span></a><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <a href="https://docs.scipy.org/doc/numpy/reference/constants.html#numpy.pi" title="View documentation for numpy.pi"><span class="n">np</span><span class="o">.</span><span class="n">pi</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">t</span></a><span class="p">)</span>
<span class="c1"># 1) RGB tuple:</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> <span class="n">ax</span> <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><span class="n">facecolor</span><span class="o">=</span><span class="p">(</span><span class="o">.</span><span class="mi">18</span><span class="p">,</span> <span class="o">.</span><span class="mi">31</span><span class="p">,</span> <span class="o">.</span><span class="mi">31</span><span class="p">))</span>
<span class="c1"># 2) hex string:</span>
<a href="../../api/_as_gen/matplotlib.axes.Axes.set_facecolor.html#matplotlib.axes.Axes.set_facecolor" title="View documentation for matplotlib.axes.Axes.set_facecolor"><span class="n">ax</span><span class="o">.</span><span class="n">set_facecolor</span></a><span class="p">(</span><span class="s1">'#eafff5'</span><span class="p">)</span>
<span class="c1"># 3) gray level string:</span>
<span class="n">ax</span><span class="o">.</span><span class="n">set_title</span><span class="p">(</span><span class="s1">'Voltage vs. time chart'</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">'0.7'</span><span class="p">)</span>
<span class="c1"># 4) single letter color string</span>
<span class="n">ax</span><span class="o">.</span><span class="n">set_xlabel</span><span class="p">(</span><span class="s1">'time (s)'</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">'c'</span><span class="p">)</span>
<span class="c1"># 5) a named color:</span>
<span class="n">ax</span><span class="o">.</span><span class="n">set_ylabel</span><span class="p">(</span><span class="s1">'voltage (mV)'</span><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">'peachpuff'</span><span class="p">)</span>
<span class="c1"># 6) a named xkcd color:</span>
<span class="n">ax</span><span class="o">.</span><span class="n">plot</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">t</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">s</span></a><span class="p">,</span> <span class="s1">'xkcd:crimson'</span><span class="p">)</span>
<span class="c1"># 7) Cn notation:</span>
<span class="n">ax</span><span class="o">.</span><span class="n">plot</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">t</span></a><span class="p">,</span> <span class="o">.</span><span class="mi">7</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">s</span></a><span class="p">,</span> <span class="n">color</span><span class="o">=</span><span class="s1">'C4'</span><span class="p">,</span> <span class="n">linestyle</span><span class="o">=</span><span class="s1">'--'</span><span class="p">)</span>
<span class="c1"># 8) tab notation:</span>
<span class="n">ax</span><span class="o">.</span><span class="n">tick_params</span><span class="p">(</span><span class="n">labelcolor</span><span class="o">=</span><span class="s1">'tab:orange'</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>
<img alt="../../_images/sphx_glr_color_demo_001.png" class="sphx-glr-single-img" src="../../_images/sphx_glr_color_demo_001.png" />
<hr class="docutils" />
<div class="section" id="references">
<h2>References<a class="headerlink" href="#references" title="Permalink to this headline">¶</a></h2>
<p>The use of the following functions, methods, classes and modules is shown
in this example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">matplotlib</span>
<a href="../../api/colors_api.html#module-matplotlib.colors" title="View documentation for matplotlib.colors"><span class="n">matplotlib</span><span class="o">.</span><span class="n">colors</span></a>
<span class="n">matplotlib</span><span class="o">.</span><span class="n">axes</span><span class="o">.</span><span class="n">Axes</span><span class="o">.</span><span class="n">plot</span>
<a href="../../api/_as_gen/matplotlib.axes.Axes.set_facecolor.html#matplotlib.axes.Axes.set_facecolor" title="View documentation for matplotlib.axes.Axes.set_facecolor"><span class="n">matplotlib</span><span class="o">.</span><span class="n">axes</span><span class="o">.</span><span class="n">Axes</span><span class="o">.</span><span class="n">set_facecolor</span></a>
<span class="n">matplotlib</span><span class="o">.</span><span class="n">axes</span><span class="o">.</span><span class="n">Axes</span><span class="o">.</span><span class="n">set_title</span>
<span class="n">matplotlib</span><span class="o">.</span><span class="n">axes</span><span class="o">.</span><span class="n">Axes</span><span class="o">.</span><span class="n">set_xlabel</span>
<span class="n">matplotlib</span><span class="o">.</span><span class="n">axes</span><span class="o">.</span><span class="n">Axes</span><span class="o">.</span><span class="n">set_ylabel</span>
<span class="n">matplotlib</span><span class="o">.</span><span class="n">axes</span><span class="o">.</span><span class="n">Axes</span><span class="o">.</span><span class="n">tick_params</span>
</pre></div>
</div>
<p class="sphx-glr-script-out">Out:</p>
<div class="sphx-glr-script-out highlight-none notranslate"><div class="highlight"><pre><span></span><function _AxesBase.tick_params at 0x7fd757431c10>
</pre></div>
</div>
<div class="sphx-glr-footer class sphx-glr-footer-example docutils container" id="sphx-glr-download-gallery-color-color-demo-py">
<div class="sphx-glr-download docutils container">
<a class="reference download internal" download="" href="../../_downloads/5081c87adb2d88b276f57b86123306cf/color_demo.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">color_demo.py</span></code></a></div>
<div class="sphx-glr-download docutils container">
<a class="reference download internal" download="" href="../../_downloads/4f3ca5340291b0059950062d95463abe/color_demo.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">color_demo.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>
<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>