Skip to content

ENH: add XKCD colorname -> hex mapping #5775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 29, 2016
Prev Previous commit
Next Next commit
MNT: add xkcd prefix + switch priority order
 - prefer the CSS4 str -> hex values because they are the 'standard'.
   The xkcd colors might be 'better', but we are not the right place to
   lead that change.  If users use CSS/HTML/X11 color in mpl they should
   expect it to match the same color set in html for embedding mpl
   figures into websites and such.

 - Provide entries in XKCD dict of all names (with and with out spaces)
   prefixed with XKCD.  Thus to get XKCD's version of blue use
   `color='xkcdblue'
  • Loading branch information
tacaswell committed Jan 5, 2016
commit b2543f67d212f3e3aa2216cd0c7b0b849f274ab8
5 changes: 4 additions & 1 deletion lib/matplotlib/_color_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,11 +961,14 @@
'green': '#15b01a',
'purple': '#7e1e9c'}

# normalize to names with no spaces
# normalize to names with no spaces and provide versions with XKCD
# prefix.
for k in list(XKCD_COLORS):
XKCD_COLORS['XKCD'+k] = XKCD_COLORS[k]
_k = k.replace(' ', '')
if _k != k:
XKCD_COLORS[_k] = XKCD_COLORS[k]
XKCD_COLORS['XKCD'+_k] = XKCD_COLORS[k]


# https://drafts.csswg.org/css-color-4/#named-colors
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class ColorConverter(object):
'w': '#ffffff'}

cache = {}
CN_LOOKUPS = [colors, ] + [COLOR_NAMES[k] for k in ['xkcd', 'css4']]
CN_LOOKUPS = [colors, ] + [COLOR_NAMES[k] for k in ['css4', 'xkcd']]

def to_rgb(self, arg):
"""
Expand Down