Skip to content

Add solarized palette as named colors #11927

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
63b8b65
add Solarized palette
josesho Aug 24, 2018
befad3c
add import solarized colors
josesho Aug 24, 2018
b1e9b57
add solarized colors to named color example
josesho Aug 24, 2018
22f03ee
add Solarized palette writeup to whats_new
josesho Aug 24, 2018
1e5ec15
fix typo
josesho Aug 24, 2018
b329729
align dict with above dict; change "solarized-" to "solarized:"
josesho Aug 24, 2018
1dc142d
align import
josesho Aug 24, 2018
c5cd04b
align within parenthesis
josesho Aug 24, 2018
4f766d3
fix reference to solarized colors
josesho Aug 24, 2018
e37e84c
update named colors example
josesho Aug 25, 2018
72716ab
align swatches; standardize swatch size and font size
josesho Aug 26, 2018
cec44bb
better control of grid layout
josesho Aug 27, 2018
57c7d00
fix missing `mcolors.`
josesho Aug 27, 2018
da7d5be
code lint
josesho Aug 27, 2018
36d14cb
removed unused functions in references
josesho Aug 27, 2018
7d9f670
add descriptions as inline comments
josesho Aug 27, 2018
6138137
revert as per issuecomment-416700193
josesho Aug 29, 2018
39eec2a
Merge branch 'add-solarized-palette-as-named-colors' of https://githu…
josesho Aug 29, 2018
59761d7
moved solarized writeup from whats_new to next_whats_new
josesho Aug 29, 2018
d4f109e
add mention of Solarized to colors.py module docstring
josesho Aug 29, 2018
fa9fda5
fix typo
josesho Aug 29, 2018
cf70a3d
fix another typo
josesho Aug 29, 2018
88c05e7
fix identation in docstring
josesho Aug 29, 2018
6dbfb50
fix broekn rst hyperlink
josesho Aug 29, 2018
00f5c60
add solarized description to docstring
josesho Aug 30, 2018
3dabeae
uncomment next_whats_new TOC chunk
josesho Aug 30, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/users/next_whats_new/solarized_palette.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Solarized palette are now named matplotlib colors
-------------------------------------------------
Ethan Schoonover's `Solarized palette <https://ethanschoonover.com/solarized/__`
is now implemented as named matplotlib colors. Comprising of 16 colors, the
colors can be accesseed by appending 'solarized:' to their name, e.g.
`solarized:cyan` refers to cyan from the Solarized palette.
10 changes: 5 additions & 5 deletions doc/users/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ revision, see the :ref:`github-stats`.
For a release, add a new section after this, then comment out the include
and toctree below by indenting them. Uncomment them after the release.

.. include:: next_whats_new/README.rst
.. toctree::
:glob:
:maxdepth: 1
.. include:: next_whats_new/README.rst
.. toctree::
:glob:
:maxdepth: 1

next_whats_new/*
next_whats_new/*

Ability to scale axis by a fixed order of magnitude
---------------------------------------------------
Expand Down
8 changes: 7 additions & 1 deletion examples/color/color_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Color Demo
==========

Matplotlib gives you 8 ways to specify colors,
Matplotlib gives you 9 ways to specify colors,

1) an RGB or RGBA tuple of float values in ``[0, 1]`` (e.g. ``(0.1, 0.2, 0.5)``
or ``(0.1, 0.2, 0.5, 0.3)``). RGBA is short for Red, Green, Blue, Alpha;
Expand All @@ -23,6 +23,12 @@
'tab:red', 'tab:purple', 'tab:brown', 'tab:pink',
'tab:gray', 'tab:olive', 'tab:cyan'}`` which are the Tableau Colors from the
'tab10' categorical palette (which is the default color cycle);
9) one of ``{'solarized:base03', 'solarized:base02', 'solarized:base01',
'solarized:base00', 'solarized:base0', 'solarized:base1', 'solarized:base2',
'solarized:base3', 'solarized:yellow', 'solarized:orange', 'solarized:red',
'solarized:magenta', 'solarized:violet', 'solarized:blue', 'solarized:cyan',
'solarized:green'}`` which are the colors from Ethan Schoonover's
`Solarized palette <https://ethanschoonover.com/solarized/>`_;.

For more information on colors in matplotlib see

Expand Down
94 changes: 58 additions & 36 deletions examples/color/named_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,77 @@
* the `matplotlib.colors` API;
* the :doc:`/gallery/color/color_demo`.
"""

import matplotlib.pyplot as plt
from matplotlib import colors as mcolors


colors = dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS)
# First, we define a custom plotting function that accepts a dictionary
# from one of matplotlib's named color palettes.
def plot_colors(colors, title, sort_colors=True, ncols=4):

import matplotlib.pyplot as plt
from matplotlib.colors import rgb_to_hsv, to_rgba

extra_rows = 2 # Additional space for title.
cell_width = 225
cell_height = 30
swatch_width = 50

# Sort colors by hue, saturation, value and name.
by_hsv = ((tuple(rgb_to_hsv(to_rgba(color)[:3])), name)
for name, color in colors.items())
if sort_colors is True:
by_hsv = sorted(by_hsv)
names = [name for hsv, name in by_hsv]

n = len(names)
nrows = (n + 1) // ncols

width = cell_width * ncols
height = cell_height * (nrows + extra_rows)
dpi = 72
fig, ax = plt.subplots(figsize=(width / dpi, height / dpi), dpi=dpi)

# Sort colors by hue, saturation, value and name.
by_hsv = sorted((tuple(mcolors.rgb_to_hsv(mcolors.to_rgba(color)[:3])), name)
for name, color in colors.items())
sorted_names = [name for hsv, name in by_hsv]
ax.set_xlim(0, width)
ax.set_ylim(height, 0)
ax.yaxis.set_visible(False)
ax.xaxis.set_visible(False)
ax.set_axis_off()
ax.text(0, cell_height, title, fontsize=20)

n = len(sorted_names)
ncols = 4
nrows = n // ncols
for i, name in enumerate(names):
row = i % nrows
col = i // nrows
y = (row + extra_rows) * cell_height

fig, ax = plt.subplots(figsize=(9, 8))
swatch_start_x = cell_width * col
swatch_end_x = cell_width * col + swatch_width
text_pos_x = cell_width * col + swatch_width + 5

# Get height and width
X, Y = fig.get_dpi() * fig.get_size_inches()
h = Y / (nrows + 1)
w = X / ncols
ax.text(text_pos_x, y, name, fontsize=14,
horizontalalignment='left',
verticalalignment='center')

for i, name in enumerate(sorted_names):
row = i % nrows
col = i // nrows
y = Y - (row * h) - h
ax.hlines(y, swatch_start_x, swatch_end_x,
color=colors[name], linewidth=20)

xi_line = w * (col + 0.05)
xf_line = w * (col + 0.25)
xi_text = w * (col + 0.3)
plt.show()

ax.text(xi_text, y, name, fontsize=(h * 0.5),
horizontalalignment='left',
verticalalignment='center')
# Display the 8 base colors in matplotlib.
plot_colors(mcolors.BASE_COLORS, "Base Colors", sort_colors=False,
ncols=3)

ax.hlines(y + h * 0.1, xi_line, xf_line,
color=colors[name], linewidth=(h * 0.6))
# Displays named colors as defined by the CSS specification.
# For more on CSS colors, see https://www.w3.org/TR/css-color-4/
plot_colors(mcolors.CSS4_COLORS, "CSS Colors")

ax.set_xlim(0, X)
ax.set_ylim(0, Y)
ax.set_axis_off()
# The Solarized palette is a 16-color palette designed for screen use.
# For more information, see https://ethanschoonover.com/solarized/
plot_colors(mcolors.SOLARIZED_COLORS, "Solarized Palette",
sort_colors=False)

fig.subplots_adjust(left=0, right=1,
top=1, bottom=0,
hspace=0, wspace=0)
plt.show()
# This displays the classic 10-color default palette in Tableau.
plot_colors(mcolors.TABLEAU_COLORS, "Tableau Palette", sort_colors=False,
ncols=2)

#############################################################################
#
Expand All @@ -73,7 +97,5 @@
matplotlib.colors
matplotlib.colors.rgb_to_hsv
matplotlib.colors.to_rgba
matplotlib.figure.Figure.get_size_inches
matplotlib.figure.Figure.subplots_adjust
matplotlib.axes.Axes.text
matplotlib.axes.Axes.hlines
23 changes: 23 additions & 0 deletions lib/matplotlib/_color_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1142,3 +1142,26 @@
'whitesmoke': '#F5F5F5',
'yellow': '#FFFF00',
'yellowgreen': '#9ACD32'}

# These are the 16 colors of the Solarized palette by Ethan Schoonover.
# See https://ethanschoonover.com/solarized/
# License: https://github.com/altercation/solarized/blob/master/LICENSE
# Copyright (c) 2011 Ethan Schoonover
SOLARIZED_COLORS = {
'solarized:base03': '#002b36',
'solarized:base02': '#073642',
'solarized:base01': '#586e75',
'solarized:base00': '#657b83',
'solarized:base0': '#839496',
'solarized:base1': '#93a1a1',
'solarized:base2': '#eee8d5',
'solarized:base3': '#fdf6e3',
'solarized:yellow': '#b58900',
'solarized:orange': '#cb4b16',
'solarized:red': '#dc322f',
'solarized:magenta': '#d33682',
'solarized:violet': '#6c71c4',
'solarized:blue': '#268bd2',
'solarized:cyan': '#2aa198',
'solarized:green': '#859900',
}
10 changes: 9 additions & 1 deletion lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
'tab:red', 'tab:purple', 'tab:brown', 'tab:pink',
'tab:gray', 'tab:olive', 'tab:cyan'}`` which are the Tableau Colors from the
'T10' categorical palette (which is the default color cycle);
* one of ``{'solarized:base03', 'solarized:base02', 'solarized:base01',
'solarized:base00', 'solarized:base0', 'solarized:base1', 'solarized:base2',
'solarized:base3', 'solarized:yellow', 'solarized:orange', 'solarized:red',
'solarized:magenta', 'solarized:violet', 'solarized:blue', 'solarized:cyan',
'solarized:green'}`` which are the colors from Ethan Schoonover's
`Solarized palette <https://ethanschoonover.com/solarized/>`_;.
* a "CN" color spec, i.e. `'C'` followed by a single digit, which is an index
into the default property cycle (``matplotlib.rcParams['axes.prop_cycle']``);
the indexing occurs at artist creation time and defaults to black if the
Expand All @@ -50,7 +56,8 @@

import numpy as np
import matplotlib.cbook as cbook
from ._color_data import BASE_COLORS, TABLEAU_COLORS, CSS4_COLORS, XKCD_COLORS
from ._color_data import (BASE_COLORS, TABLEAU_COLORS, CSS4_COLORS,
XKCD_COLORS, SOLARIZED_COLORS)


class _ColorMapping(dict):
Expand All @@ -69,6 +76,7 @@ def __delitem__(self, key):

_colors_full_map = {}
# Set by reverse priority order.
_colors_full_map.update(SOLARIZED_COLORS)
_colors_full_map.update(XKCD_COLORS)
_colors_full_map.update({k.replace('grey', 'gray'): v
for k, v in XKCD_COLORS.items()
Expand Down