Skip to content

Commit 30ffa63

Browse files
committed
Restore CSS/xkcd comparison plot.
1 parent 3c1d4e6 commit 30ffa63

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

doc/users/colors.rst

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,57 @@
44
Specifying Colors
55
*****************
66

7-
In almost all places in matplotlib where a color can be specified by the user it can be provided as:
7+
In almost all places in matplotlib where a color can be specified by the user
8+
it can be provided as:
89

910
* ``(r, g, b)`` tuples
1011
* ``(r, g, b, a)`` tuples
1112
* hex string, ex ``#OFOFOF``
1213
* float value between [0, 1] for gray level
1314
* One of ``{'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'}``
14-
* valid css4/X11 color names
15-
* valid name from the `XKCD color survey
15+
* valid CSS4/X11 color names
16+
* valid name from the `xkcd color survey
1617
<http://blog.xkcd.com/2010/05/03/color-survey-results/>`__ These
1718
names are prefixed with ``'xkcd:'`` (e.g., ``'xkcd:sky blue'``) to
1819
prevent name clashes with the CSS4/X11 names.
1920

2021
All string specifications of color are case-insensitive.
2122

2223
Internally, mpl is moving to storing all colors as RGBA float quadruples.
24+
25+
There are 95 (out of 148 colors in the css color list) conflicts between the
26+
CSS4/X11 names and the xkcd names. Given that the former are the standard
27+
color names of the web, matplotlib should follow them. Thus, xkcd color names
28+
are prefixed with ``'xkcd:'``, for example ``'blue'`` maps to ``'#0000FF'``
29+
where as ``'xkcd:blue'`` maps to ``'#0343DF'``.
30+
31+
.. plot::
32+
33+
import matplotlib.pyplot as plt
34+
import matplotlib._color_data as mcd
35+
import matplotlib.patches as mpatch
36+
37+
overlap = {name for name in mcd.CSS4_COLORS
38+
if "xkcd:" + name in mcd.XKCD_COLORS}
39+
40+
fig = plt.figure(figsize=[4.8, 16])
41+
ax = fig.add_axes([0, 0, 1, 1])
42+
43+
for j, n in enumerate(sorted(overlap, reverse=True)):
44+
cn = mcd.CSS4_COLORS[n]
45+
xkcd = mcd.XKCD_COLORS["xkcd:" + n].upper()
46+
if cn != xkcd:
47+
print(n, cn, xkcd)
48+
49+
r1 = mpatch.Rectangle((0, j), 1, 1, color=cn)
50+
r2 = mpatch.Rectangle((1, j), 1, 1, color=xkcd)
51+
txt = ax.text(2, j+.5, ' ' + n, va='center', fontsize=10)
52+
ax.add_patch(r1)
53+
ax.add_patch(r2)
54+
ax.axhline(j, color='k')
55+
56+
ax.text(.5, j + .1, 'X11', ha='center')
57+
ax.text(1.5, j + .1, 'XKCD', ha='center')
58+
ax.set_xlim(0, 3)
59+
ax.set_ylim(0, j + 1)
60+
ax.axis('off')

0 commit comments

Comments
 (0)