From 0d8449f9a1bf5fc3738e7945caeaebe5cf2faca2 Mon Sep 17 00:00:00 2001 From: Matthew Feickert Date: Sun, 18 May 2025 00:46:52 -0600 Subject: [PATCH 1/3] ENH: Add Petroff 6 and 8 color cycle style sheets * Add the 6 color and the 8 color Petroff color cycles from Matthew A. Petroff, Accessible Color Sequences for Data Visualization https://arxiv.org/abs/2107.02270. The 10 color cycle was added in PR 27851 which landed in Matplotlib v3.10.0. --- lib/matplotlib/_cm.py | 23 +++++++++++++++++++ lib/matplotlib/colors.py | 2 ++ .../mpl-data/stylelib/petroff6.mplstyle | 5 ++++ .../mpl-data/stylelib/petroff8.mplstyle | 5 ++++ 4 files changed, 35 insertions(+) create mode 100644 lib/matplotlib/mpl-data/stylelib/petroff6.mplstyle create mode 100644 lib/matplotlib/mpl-data/stylelib/petroff8.mplstyle diff --git a/lib/matplotlib/_cm.py b/lib/matplotlib/_cm.py index b942d1697934..d3f4632108a8 100644 --- a/lib/matplotlib/_cm.py +++ b/lib/matplotlib/_cm.py @@ -1365,6 +1365,29 @@ def _gist_yarg(x): return 1 - x (0.8509803921568627, 0.8509803921568627, 0.8509803921568627 ), # d9d9d9 ) +# Colorblind accessible palettes from +# Matthew A. Petroff, Accessible Color Sequences for Data Visualization +# https://arxiv.org/abs/2107.02270 + +_petroff6_data = ( + (0.3411764705882353, 0.5647058823529412, 0.9882352941176471), # 5790fc + (0.9725490196078431, 0.611764705882353, 0.12549019607843137), # f89c20 + (0.8941176470588236, 0.1450980392156863, 0.21176470588235294), # e42536 + (0.5882352941176471, 0.2901960784313726, 0.5450980392156862), # 964a8b + (0.611764705882353, 0.611764705882353, 0.6313725490196078), # 9c9ca1 + (0.47843137254901963, 0.12941176470588237, 0.8666666666666667), # 7a21dd +) + +_petroff8_data = ( + (0.09411764705882353, 0.27058823529411763, 0.984313725490196), # 1845fb + (1.0, 0.3686274509803922, 0.00784313725490196), # ff5e02 + (0.788235294117647, 0.12156862745098039, 0.08627450980392157), # c91f16 + (0.7843137254901961, 0.28627450980392155, 0.6627450980392157), # c849a9 + (0.6784313725490196, 0.6784313725490196, 0.49019607843137253), # adad7d + (0.5254901960784314, 0.7843137254901961, 0.8666666666666667), # 86c8dd + (0.3411764705882353, 0.5529411764705883, 1.0), # 578dff + (0.396078431372549, 0.38823529411764707, 0.39215686274509803), # 656364 +) _petroff10_data = ( (0.24705882352941178, 0.5647058823529412, 0.8549019607843137), # 3f90da diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index 9bd808074c1f..d6636e0e8669 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -131,6 +131,8 @@ class ColorSequenceRegistry(Mapping): 'Set1': _cm._Set1_data, 'Set2': _cm._Set2_data, 'Set3': _cm._Set3_data, + 'petroff6': _cm._petroff6_data, + 'petroff8': _cm._petroff8_data, 'petroff10': _cm._petroff10_data, } diff --git a/lib/matplotlib/mpl-data/stylelib/petroff6.mplstyle b/lib/matplotlib/mpl-data/stylelib/petroff6.mplstyle new file mode 100644 index 000000000000..ff227eba45ba --- /dev/null +++ b/lib/matplotlib/mpl-data/stylelib/petroff6.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', ['5790fc', 'f89c20', 'e42536', '964a8b', '9c9ca1', '7a21dd']) +patch.facecolor: 5790fc diff --git a/lib/matplotlib/mpl-data/stylelib/petroff8.mplstyle b/lib/matplotlib/mpl-data/stylelib/petroff8.mplstyle new file mode 100644 index 000000000000..0228f736ddea --- /dev/null +++ b/lib/matplotlib/mpl-data/stylelib/petroff8.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', ['1845fb', 'ff5e02', 'c91f16', 'c849a9', 'adad7d', '86c8dd', '578dff', '656364']) +patch.facecolor: 1845fb From 324e7f9cade5abbc873d798c6114f4275592f506 Mon Sep 17 00:00:00 2001 From: Matthew Feickert Date: Sun, 18 May 2025 01:09:29 -0600 Subject: [PATCH 2/3] TST: Add 6 and 8 color Petroff color sequences to tests * Verify they appear in plt.color_sequences. --- lib/matplotlib/tests/test_colors.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_colors.py b/lib/matplotlib/tests/test_colors.py index 8d0f3467f045..df3f65bdb2dc 100644 --- a/lib/matplotlib/tests/test_colors.py +++ b/lib/matplotlib/tests/test_colors.py @@ -1704,7 +1704,8 @@ 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', 'petroff10'] + 'Accent', 'Dark2', 'Set1', 'Set2', 'Set3', 'petroff6', 'petroff8', + 'petroff10'] assert len(plt.color_sequences['tab10']) == 10 assert len(plt.color_sequences['tab20']) == 20 From b89e4ced8cbbe9df7556c05c1d5014f86a2f299c Mon Sep 17 00:00:00 2001 From: Matthew Feickert Date: Sun, 18 May 2025 01:21:11 -0600 Subject: [PATCH 3/3] DOC: Add 'What's New' entry for 6 and 8 Petorff color cycles * Note the addition of 'petroff6' and 'petroff8' and give an example of how to load them. --- ...x_and_eight_color_petroff_color_cycles.rst | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 doc/users/next_whats_new/six_and_eight_color_petroff_color_cycles.rst diff --git a/doc/users/next_whats_new/six_and_eight_color_petroff_color_cycles.rst b/doc/users/next_whats_new/six_and_eight_color_petroff_color_cycles.rst new file mode 100644 index 000000000000..3b17b4f68868 --- /dev/null +++ b/doc/users/next_whats_new/six_and_eight_color_petroff_color_cycles.rst @@ -0,0 +1,21 @@ +Six and eight color Petroff color cycles +---------------------------------------- + +The six and eight color accessible Petroff color cycles are named 'petroff6' and +'petroff8'. +They compliment the existing 'petroff10' color cycle, added in `Matplotlib 3.10.0`_ + +For more details see +`Petroff, M. A.: "Accessible Color Sequences for Data Visualization" +`_. +To load the 'petroff6' color cycle in place of the default:: + + import matplotlib.pyplot as plt + plt.style.use('petroff6') + +or to load the 'petroff8' color cycle:: + + import matplotlib.pyplot as plt + plt.style.use('petroff8') + +.. _Matplotlib 3.10.0: https://matplotlib.org/stable/users/prev_whats_new/whats_new_3.10.0.html#new-more-accessible-color-cycle