Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9655f45

Browse filesBrowse files
committed
Merge pull request matplotlib#5775 from tacaswell/enh_xkcd_colors
ENH: add XKCD colorname -> hex mapping
2 parents d399f25 + 9687f65 commit 9655f45
Copy full SHA for 9655f45

File tree

Expand file treeCollapse file tree

6 files changed

+1225
-168
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+1225
-168
lines changed

‎doc/users/beginner.rst

Copy file name to clipboardExpand all lines: doc/users/beginner.rst
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ Beginner's Guide
2020
legend_guide.rst
2121
annotations_guide.rst
2222
screenshots.rst
23+
colors.rst
2324
colormaps.rst
2425
colormapnorms.rst
25-
26-
27-

‎doc/users/colors.rst

Copy file name to clipboard
+71Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
.. _colors:
2+
3+
*****************
4+
Specifying Colors
5+
*****************
6+
7+
In almost all places in matplotlib where a color can be specified by the user it can be provided as:
8+
9+
* ``(r, g, b)`` tuples
10+
* ``(r, g, b, a)`` tuples
11+
* hex string, ex ``#OFOFOF``
12+
* float value between [0, 1] for gray level
13+
* One of ``{'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'}``
14+
* valid css4/X11 color names
15+
* valid name from the `XKCD color survey
16+
<http://blog.xkcd.com/2010/05/03/color-survey-results/>`__ These
17+
names are available both with and with out spaces. In the case of name clashes
18+
the css/X11 names have priority. To ensure colors
19+
from the XKCD mapping are used prefix the space-less name with
20+
``'XKCD'``.
21+
22+
All string specifications of color are case-insensitive.
23+
24+
Internally, mpl is moving to storing all colors as RGBA float quadruples.
25+
26+
Name clash between CSS4/X11 and XKCD
27+
------------------------------------
28+
29+
The color names in the XKCD survey include spaces (unlike css4/X11
30+
names). Matplotlib exposes all of the XKCD colors both with and
31+
without spaces.
32+
33+
There are 95 (out of 148 colors in the css color list) conflicts
34+
between the css4/X11 names and the XKCD names. Given that these are
35+
the standard color names of the web, matplotlib should follow these
36+
conventions. To accesses the XKCD colors which are shadowed by css4,
37+
prefix the colorname with ``'XKCD'``, for example ``'blue'`` maps to
38+
``'#0000FF'`` where as ``'XKCDblue'`` maps to ``'#0343DF'``.
39+
40+
.. plot::
41+
42+
import matplotlib.pyplot as plt
43+
import matplotlib._color_data as mcd
44+
45+
import matplotlib.patches as mpatch
46+
overlap = (set(mcd.CSS4_COLORS) & set(mcd.XKCD_COLORS))
47+
48+
fig = plt.figure(figsize=[4.8, 16])
49+
ax = fig.add_axes([0, 0, 1, 1])
50+
51+
j = 0
52+
53+
for n in sorted(overlap, reverse=True):
54+
cn = mcd.CSS4_COLORS[n]
55+
xkcd = mcd.XKCD_COLORS[n].upper()
56+
if cn != xkcd:
57+
print (n, cn, xkcd)
58+
59+
r1 = mpatch.Rectangle((0, j), 1, 1, color=cn)
60+
r2 = mpatch.Rectangle((1, j), 1, 1, color=xkcd)
61+
txt = ax.text(2, j+.5, ' ' + n, va='center', fontsize=10)
62+
ax.add_patch(r1)
63+
ax.add_patch(r2)
64+
ax.axhline(j, color='k')
65+
j += 1
66+
67+
ax.text(.5, j+.1, 'X11', ha='center')
68+
ax.text(1.5, j+.1, 'XKCD', ha='center')
69+
ax.set_xlim(0, 3)
70+
ax.set_ylim(0, j + 1)
71+
ax.axis('off')

‎doc/users/index.rst

Copy file name to clipboardExpand all lines: doc/users/index.rst
+1-4Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@ User's Guide
1616
configuration.rst
1717
beginner.rst
1818
developer.rst
19+
colors.rst
1920
whats_new.rst
2021
github_stats.rst
2122
license.rst
2223
credits.rst
23-
24-
25-
26-

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.