Skip to content

Add ten-color accessible color cycle as style sheet #27851

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 4 commits into from
Aug 22, 2024
Merged
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
19 changes: 19 additions & 0 deletions doc/users/next_whats_new/ccs_color_cycle.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
New more-accessible color cycle
-------------------------------

A new color cycle named 'petroff10' was added. This cycle was constructed using a
combination of algorithmically-enforced accessibility constraints, including
color-vision-deficiency modeling, and a machine-learning-based aesthetics model
developed from a crowdsourced color-preference survey. It aims to be both
generally pleasing aesthetically and colorblind accessible such that it could
serve as a default in the aim of universal design. For more details
see `Petroff, M. A.: "Accessible Color Sequences for Data Visualization"
<https://arxiv.org/abs/2107.02270>`_ and related `SciPy talk`_. A demonstration
is included in the style sheets reference_. To load this color cycle in place
of the default::

import matplotlib.pyplot as plt
plt.style.use('petroff10')

.. _reference: https://matplotlib.org/gallery/style_sheets/style_sheets_reference.html
.. _SciPy talk: https://www.youtube.com/watch?v=Gapv8wR5DYU
14 changes: 14 additions & 0 deletions lib/matplotlib/_cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,20 @@ def _gist_yarg(x): return 1 - x
)


_petroff10_data = (
(0.24705882352941178, 0.5647058823529412, 0.8549019607843137), # 3f90da
(1.0, 0.6627450980392157, 0.054901960784313725), # ffa90e
(0.7411764705882353, 0.12156862745098039, 0.00392156862745098), # bd1f01
(0.5803921568627451, 0.6431372549019608, 0.6352941176470588), # 94a4a2
(0.5137254901960784, 0.17647058823529413, 0.7137254901960784), # 832db6
(0.6627450980392157, 0.4196078431372549, 0.34901960784313724), # a96b59
(0.9058823529411765, 0.38823529411764707, 0.0), # e76300
(0.7254901960784313, 0.6745098039215687, 0.4392156862745098), # b9ac70
(0.44313725490196076, 0.4588235294117647, 0.5058823529411764), # 717581
(0.5725490196078431, 0.8549019607843137, 0.8666666666666667), # 92dadd
)


datad = {
'Blues': _Blues_data,
'BrBG': _BrBG_data,
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class ColorSequenceRegistry(Mapping):
'Set1': _cm._Set1_data,
'Set2': _cm._Set2_data,
'Set3': _cm._Set3_data,
'petroff10': _cm._petroff10_data,
}

def __init__(self):
Expand Down
5 changes: 5 additions & 0 deletions lib/matplotlib/mpl-data/stylelib/petroff10.mplstyle
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Color cycle survey palette from Petroff (2021):
# https://arxiv.org/abs/2107.02270
# https://github.com/mpetroff/accessible-color-cycles
axes.prop_cycle: cycler('color', ['3f90da', 'ffa90e', 'bd1f01', '94a4a2', '832db6', 'a96b59', 'e76300', 'b9ac70', '717581', '92dadd'])
patch.facecolor: 3f90da
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,7 @@ def test_color_sequences():
assert plt.color_sequences is matplotlib.color_sequences # same registry
assert list(plt.color_sequences) == [
'tab10', 'tab20', 'tab20b', 'tab20c', 'Pastel1', 'Pastel2', 'Paired',
'Accent', 'Dark2', 'Set1', 'Set2', 'Set3']
'Accent', 'Dark2', 'Set1', 'Set2', 'Set3', 'petroff10']
assert len(plt.color_sequences['tab10']) == 10
assert len(plt.color_sequences['tab20']) == 20

Expand Down
Loading