Skip to content

Introducing Spectral Colors #29517

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions doc/api/colors_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,5 @@ as dictionaries that map color names to hex strings.
.. py:data:: CSS4_COLORS

.. py:data:: XKCD_COLORS

.. py:data:: SPECTRAL_COLORS
13 changes: 12 additions & 1 deletion galleries/examples/color/named_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@
from matplotlib.patches import Rectangle


def plot_colortable(colors, *, ncols=4, sort_colors=True):
def plot_colortable(colors, *, ncols=4, sort_colors=True, sample=False):

cell_width = 212
cell_height = 22
swatch_width = 48
margin = 12

if sample:
colors = dict(list(colors.items())[::10])

# Sort colors by hue, saturation, value and name.
if sort_colors is True:
names = sorted(
Expand Down Expand Up @@ -97,6 +100,14 @@ def plot_colortable(colors, *, ncols=4, sort_colors=True):
plot_colortable(mcolors.CSS4_COLORS)
plt.show()

# %%
# ---------------
# Spectral Colors
# ---------------
# The full visible spectrum from 390nm to 780nm is supported in integers
# e.g. ``"405nm"``. A sub sample of the defined colors by wavelength is shown below.
plot_colortable(mcolors.SPECTRAL_COLORS, ncols=4, sort_colors=False, sample=True)

# %%
# -----------
# XKCD Colors
Expand Down
4 changes: 4 additions & 0 deletions galleries/users_explain/colors/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
| `xkcd color survey`_ with ``'xkcd:'``| - ``'xkcd:eggshell'`` |
| prefix. | |
+--------------------------------------+--------------------------------------+
| Case-insensitive spectral colors | - ``'405nm'`` |
| specified by wavelength in nano | - ``'525nm'`` |
| meters (supported range 390..780) | - ``'650nm'`` |
+--------------------------------------+--------------------------------------+
| Case-insensitive Tableau Colors from | - ``'tab:blue'`` |
| 'T10' categorical palette. | - ``'tab:orange'`` |
| | - ``'tab:green'`` |
Expand Down
Loading
Loading