diff --git a/doc/users/next_whats_new/ccs_color_cycle.rst b/doc/users/next_whats_new/ccs_color_cycle.rst new file mode 100644 index 000000000000..2c9c0c85145c --- /dev/null +++ b/doc/users/next_whats_new/ccs_color_cycle.rst @@ -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" +`_ 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 diff --git a/lib/matplotlib/_cm.py b/lib/matplotlib/_cm.py index 59d260107f3b..b942d1697934 100644 --- a/lib/matplotlib/_cm.py +++ b/lib/matplotlib/_cm.py @@ -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, diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index 5f40e7b0fb9a..7c127fce7819 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -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): diff --git a/lib/matplotlib/mpl-data/stylelib/petroff10.mplstyle b/lib/matplotlib/mpl-data/stylelib/petroff10.mplstyle new file mode 100644 index 000000000000..62d1262a09cd --- /dev/null +++ b/lib/matplotlib/mpl-data/stylelib/petroff10.mplstyle @@ -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 diff --git a/lib/matplotlib/tests/test_colors.py b/lib/matplotlib/tests/test_colors.py index d99dd91e9cf5..3fd7cbdc9d46 100644 --- a/lib/matplotlib/tests/test_colors.py +++ b/lib/matplotlib/tests/test_colors.py @@ -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