Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9ea3836

Browse files
committed
DOCS: Specifying Colors tutorial format & arrange
1 parent 51ab42c commit 9ea3836

1 file changed

Lines changed: 86 additions & 57 deletions

File tree

tutorials/colors/colors.py

Lines changed: 86 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,85 @@
55
66
Matplotlib recognizes the following formats to specify a color:
77
8-
* an RGB or RGBA (red, green, blue, alpha) tuple of float values in closed
9-
interval ``[0, 1]`` (e.g., ``(0.1, 0.2, 0.5)`` or ``(0.1, 0.2, 0.5, 0.3)``);
10-
* a hex RGB or RGBA string (e.g., ``'#0f0f0f'`` or ``'#0f0f0f80'``;
11-
case-insensitive);
12-
* a shorthand hex RGB or RGBA string, equivalent to the hex RGB or RGBA
13-
string obtained by duplicating each character, (e.g., ``'#abc'``, equivalent
14-
to ``'#aabbcc'``, or ``'#abcd'``, equivalent to ``'#aabbccdd'``;
15-
case-insensitive);
16-
* a string representation of a float value in ``[0, 1]`` inclusive for gray
17-
level (e.g., ``'0.8'`` for light gray);
18-
* one of the characters ``{'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'}``, which
19-
are short-hand notations for shades of blue, green, red, cyan, magenta,
20-
yellow, black, and white. Note that the colors ``'g', 'c', 'm', 'y'`` do not
21-
coincide with the X11/CSS4 colors. Their particular shades were chosen for
22-
better visibility of colored lines against typical backgrounds.
23-
* a X11/CSS4 color name (case-insensitive);
24-
* a name from the `xkcd color survey`_, prefixed with ``'xkcd:'`` (e.g.,
25-
``'xkcd:sky blue'``; case insensitive);
26-
* one of the Tableau Colors from the 'T10' categorical palette (the default
27-
color cycle): ``{'tab:blue', 'tab:orange', 'tab:green', 'tab:red',
28-
'tab:purple', 'tab:brown', 'tab:pink', 'tab:gray', 'tab:olive', 'tab:cyan'}``
29-
(case-insensitive);
30-
* a "CN" color spec, i.e. ``'C'`` followed by a number, which is an index into
31-
the default property cycle (:rc:`axes.prop_cycle`); the indexing is intended
32-
to occur at rendering time, and defaults to black if the cycle does not
33-
include color.
8+
+--------------------------------------+--------------------------------------+
9+
| Format | Example |
10+
+======================================+======================================+
11+
| RGB or RGBA (red, green, blue, alpha)| - ``(0.1, 0.2, 0.5)`` |
12+
| tuple of float values in a closed | - ``(0.1, 0.2, 0.5, 0.3)`` |
13+
| interval [0, 1] | |
14+
+--------------------------------------+--------------------------------------+
15+
| Case-insensitive hex RGB or RGBA | - ``'#0f0f0f'`` |
16+
| string | - ``'#0f0f0f80'`` |
17+
+--------------------------------------+--------------------------------------+
18+
| Case-insensitive shorthand equivalent| - ``'#abc'`` as ``'#aabbcc'`` |
19+
| string of RGB orRGBA from duplicated | - ``'#abcd'`` as ``'#aabbccdd'`` |
20+
| characters | |
21+
+--------------------------------------+--------------------------------------+
22+
| String representation of float value | - ``'0.8'`` as light gray |
23+
| in closed interval ``[0, 1]``, | |
24+
| inclusive for gray level | |
25+
+--------------------------------------+--------------------------------------+
26+
| Single character shorthand notation | - ``'b'`` as blue |
27+
| for shades of colors | - ``'g'`` as green |
28+
| | - ``'r'`` as red |
29+
| .. note:: The colors green, cyan, | - ``'c'`` as cyan |
30+
| magenta, and yellow do not | - ``'m'`` as magenta |
31+
| coincide with X11/CSS4 | - ``'y'`` as yellow |
32+
| colors. | - ``'k'`` as black |
33+
| | - ``'w'`` as white |
34+
+--------------------------------------+--------------------------------------+
35+
| Case-insensitive color name from | - ``'xkcd:sky blue'`` |
36+
| `xkcd color survey`_ with ``'xkcd:'``| - ``'xkcd:eggshell'`` |
37+
| prefix | |
38+
+--------------------------------------+--------------------------------------+
39+
| Case-insensitive Tableau Colors from | - 'tab:blue' |
40+
| 'T10' categorical palette | - 'tab:orange' |
41+
| | - 'tab:green' |
42+
| | - 'tab:red' |
43+
| | - 'tab:purple' |
44+
| .. note:: This is the default color | - 'tab:brown' |
45+
| cycle. | - 'tab:pink' |
46+
| | - 'tab:gray' |
47+
| | - 'tab:olive' |
48+
| | - 'tab:cyan' |
49+
+--------------------------------------+--------------------------------------+
50+
| "CN" color spec where ``'C'`` | - ``'C0'`` |
51+
| precedes a number acting as an index | - ``'C1'`` |
52+
| into the default property cycle +--------------------------------------+
53+
| | :rc:`axes.prop_cycle` |
54+
| .. note:: Indexing occurs at | |
55+
| rendering time and defaults| |
56+
| to black if cycle does not | |
57+
| inlcude color. | |
58+
+--------------------------------------+--------------------------------------+
3459
3560
.. _xkcd color survey: https://xkcd.com/color/rgb/
3661
37-
"Red", "Green", and "Blue" are the intensities of those colors, the combination
38-
of which span the colorspace.
62+
"Red", "Green", and "Blue" are the intensities of those colors. In combination,
63+
they represent the colorspace.
3964
40-
How "Alpha" behaves depends on the ``zorder`` of the Artist. Higher
41-
``zorder`` Artists are drawn on top of lower Artists, and "Alpha" determines
42-
whether the lower artist is covered by the higher.
43-
If the old RGB of a pixel is ``RGBold`` and the RGB of the
44-
pixel of the Artist being added is ``RGBnew`` with Alpha ``alpha``,
45-
then the RGB of the pixel is updated to:
46-
``RGB = RGBOld * (1 - Alpha) + RGBnew * Alpha``. Alpha
47-
of 1 means the old color is completely covered by the new Artist, Alpha of 0
48-
means that pixel of the Artist is transparent.
65+
"Alpha" depends on the ``zorder`` of the Artist. Matplotlib draws higher
66+
``zorder`` Artists on top of lower Artists. "Alpha" determines
67+
whether the lower Artist is covered by the higher.
4968
50-
For more information on colors in matplotlib see
69+
If the previous RGB of a pixel is ``RGBold`` and the RGB of the pixel of the
70+
added Artist is ``RGBnew`` with Alpha ``alpha``, then the RGB of the pixel
71+
updates to: ``RGB = RGBOld * (1 - Alpha) + RGBnew * Alpha``.
5172
52-
* the :doc:`/gallery/color/color_demo` example;
53-
* the `matplotlib.colors` API;
54-
* the :doc:`/gallery/color/named_colors` example.
73+
Alpha of 1 indicates the new Artist completely covering the previous color.
74+
Alpha of 0 indicates that pixel of the Artist is transparent.
75+
76+
.. seealso::
77+
78+
The following links provide more information on colors in Matplotlib.
79+
* :doc:`/gallery/color/color_demo` Example
80+
* `matplotlib.colors` API
81+
* :doc:`/gallery/color/named_colors` Example
5582
5683
"CN" color selection
5784
--------------------
5885
59-
"CN" colors are converted to RGBA as soon as the artist is created. For
60-
example,
86+
"CN" colors convert to RGBA when creating Artists.
6187
"""
6288

6389

@@ -78,33 +104,34 @@ def demo(sty):
78104
ax.plot(th, np.sin(th), 'C2', label='C2')
79105
ax.legend()
80106

107+
81108
demo('default')
82109
demo('seaborn')
83110

84111
###############################################################################
85-
# will use the first color for the title and then plot using the second
86-
# and third colors of each style's :rc:`axes.prop_cycle`.
87-
#
112+
# The first color ``'C0'`` is the title. Each plot uses the second and third
113+
# colors of each style's :rc:`axes.prop_cycle`. They are ``'C1'`` and ``'C2'``,
114+
# respectively.
88115
#
89116
# .. _xkcd-colors:
90117
#
91118
# xkcd v X11/CSS4
92119
# ---------------
93120
#
94-
# The xkcd colors are derived from a user survey conducted by the
95-
# webcomic xkcd. `Details of the survey are available on the xkcd blog
121+
# The xkcd colors come from a user survey conducted by the webcomic xkcd.
122+
# Details of the survey are available on the `xkcd blog
96123
# <https://blog.xkcd.com/2010/05/03/color-survey-results/>`__.
97124
#
98-
# Out of 148 colors in the CSS color list, there are 95 name collisions
99-
# between the X11/CSS4 names and the xkcd names, all but 3 of which have
100-
# different hex values. For example ``'blue'`` maps to ``'#0000FF'``
101-
# where as ``'xkcd:blue'`` maps to ``'#0343DF'``. Due to these name
102-
# collisions all of the xkcd colors have ``'xkcd:'`` prefixed. As noted in
103-
# the blog post, while it might be interesting to re-define the X11/CSS4 names
104-
# based on such a survey, we do not do so unilaterally.
125+
# There are 95 out of 148 colors with name collisions between the X11/CSS4
126+
# names and the xkcd names. Only three of these colors have the same hex
127+
# values.
128+
#
129+
# For example, ``'blue'`` maps to ``'#0000FF'`` whereas ``'xkcd:blue'`` maps to
130+
# ``'#0343DF'``. Due to these name collisions, all xkcd colors have the
131+
# ``'xkcd:'`` prefix.
105132
#
106-
# The name collisions are shown in the table below; the color names
107-
# where the hex values agree are shown in bold.
133+
# The visual below shows name collisions. Color names where hex values agree
134+
# are bold.
108135

109136
import matplotlib._color_data as mcd
110137
import matplotlib.patches as mpatch
@@ -135,3 +162,5 @@ def demo(sty):
135162
ax.set_xlim(0, 3)
136163
ax.set_ylim(0, j + 2)
137164
ax.axis('off')
165+
166+
plt.show()

0 commit comments

Comments
 (0)