Skip to content

Commit bbf01d4

Browse files
authored
Implements the Okabe-Ito accessible colormap. (#30821)
Add Okabe_Ito color sequence (https://jfly.uni-koeln.de/color/)
1 parent 0088182 commit bbf01d4

File tree

8 files changed

+57
-9
lines changed

8 files changed

+57
-9
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Okabe-Ito accessible color sequence
2+
-----------------------------------
3+
4+
Matplotlib now includes the `Okabe-Ito color sequence`_. Its colors remain distinguishable for common forms of color-vision deficiency and when printed.
5+
6+
.. _Okabe-Ito color sequence: https://jfly.uni-koeln.de/color/#pallet
7+
8+
For example, to set it as the default colormap for your plots and image-like artists, use:
9+
10+
.. code-block:: python
11+
12+
import matplotlib.pyplot as plt
13+
from cycler import cycler
14+
15+
plt.rcParams['axes.prop_cycle'] = cycler('color', plt.colormaps['okabe_ito'].colors)
16+
plt.rcParams['image.cmap'] = 'okabe_ito'
17+
18+
Or, when creating plots, you can pass it explicitly:
19+
20+
.. plot::
21+
22+
import matplotlib.pyplot as plt
23+
24+
colors = plt.colormaps['okabe_ito'].colors
25+
x = range(5)
26+
for i, c in enumerate(colors):
27+
plt.plot(x, [v*(i+1) for v in x], color=c, label=f'line {i}')
28+
plt.legend()
29+
plt.show()

galleries/examples/color/color_sequences.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ def plot_color_sequences(names, ax):
3838

3939
built_in_color_sequences = [
4040
'tab10', 'tab20', 'tab20b', 'tab20c', 'Pastel1', 'Pastel2', 'Paired',
41-
'Accent', 'Dark2', 'Set1', 'Set2', 'Set3', 'petroff6', 'petroff8',
42-
'petroff10']
41+
'Accent', 'okabe_ito', 'Dark2', 'Set1', 'Set2', 'Set3', 'petroff6',
42+
'petroff8', 'petroff10']
4343

4444

4545
fig, ax = plt.subplots(figsize=(6.4, 9.6), layout='constrained')

galleries/examples/color/colormap_reference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
'berlin', 'managua', 'vanimo']),
3333
('Cyclic', ['twilight', 'twilight_shifted', 'hsv']),
3434
('Qualitative', [
35-
'Pastel1', 'Pastel2', 'Paired', 'Accent',
35+
'Pastel1', 'Pastel2', 'Paired', 'Accent', 'okabe_ito',
3636
'Dark2', 'Set1', 'Set2', 'Set3',
3737
'tab10', 'tab20', 'tab20b', 'tab20c']),
3838
('Miscellaneous', [

galleries/users_explain/colors/colormaps.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ def plot_color_gradients(category, cmap_list):
230230
# These would not be good options for use as perceptual colormaps.
231231

232232
plot_color_gradients('Qualitative',
233-
['Pastel1', 'Pastel2', 'Paired', 'Accent', 'Dark2',
234-
'Set1', 'Set2', 'Set3', 'tab10', 'tab20', 'tab20b',
235-
'tab20c'])
233+
['Pastel1', 'Pastel2', 'Paired', 'Accent', 'okabe_ito',
234+
'Dark2', 'Set1', 'Set2', 'Set3', 'tab10', 'tab20',
235+
'tab20b', 'tab20c'])
236236

237237
# %%
238238
# Miscellaneous

lib/matplotlib/_cm.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,6 @@ def _g36(x): return 2 * x - 1
852852
(0.50196078431372548, 0.0 , 0.14901960784313725)
853853
)
854854

855-
856855
# ColorBrewer's qualitative maps, implemented using ListedColormap
857856
# for use with mpl.colors.NoNorm
858857

@@ -878,6 +877,22 @@ def _g36(x): return 2 * x - 1
878877
(0.4, 0.4, 0.4 ),
879878
)
880879

880+
# Okabe-Ito accessible and print-friendly color palette.
881+
# By Masataka Okabe (Jikei Medical School) and Kei Ito (University of Tokyo).
882+
# Qualitative color palette that is unambiguous regardless of whether
883+
# the viewer has colorblindness. https://jfly.uni-koeln.de/color/#pallet
884+
885+
_okabe_ito_data = (
886+
(0.0, 0.0, 0.0), # black
887+
(0.9019607843137255, 0.6235294117647059, 0.0), # e69f00
888+
(0.33725490196078434, 0.7058823529411765, 0.9137254901960784), # 56b4e9
889+
(0.0, 0.6196078431372549, 0.45098039215686275), # 009e73
890+
(0.9411764705882353, 0.8941176470588236, 0.25882352941176473), # f0e442
891+
(0.0, 0.4470588235294118, 0.6980392156862745), # 0072b2
892+
(0.8352941176470589, 0.3686274509803922, 0.0), # d55e00
893+
(0.8, 0.4745098039215686, 0.6549019607843137), # cc79a7
894+
)
895+
881896
_Paired_data = (
882897
(0.65098039215686276, 0.80784313725490198, 0.8901960784313725 ),
883898
(0.12156862745098039, 0.47058823529411764, 0.70588235294117652),
@@ -1469,6 +1484,7 @@ def _gist_yarg(x): return 1 - x
14691484
'winter': _winter_data,
14701485
# Qualitative
14711486
'Accent': {'listed': _Accent_data},
1487+
'okabe_ito': {'listed': _okabe_ito_data},
14721488
'Dark2': {'listed': _Dark2_data},
14731489
'Paired': {'listed': _Paired_data},
14741490
'Pastel1': {'listed': _Pastel1_data},

lib/matplotlib/cm.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ terrain: colors.Colormap
9797
winter: colors.Colormap
9898
Accent: colors.Colormap
9999
Dark2: colors.Colormap
100+
okabe_ito: colors.Colormap
100101
Paired: colors.Colormap
101102
Pastel1: colors.Colormap
102103
Pastel2: colors.Colormap
@@ -188,6 +189,7 @@ terrain_r: colors.Colormap
188189
winter_r: colors.Colormap
189190
Accent_r: colors.Colormap
190191
Dark2_r: colors.Colormap
192+
okabe_ito_r: colors.Colormap
191193
Paired_r: colors.Colormap
192194
Pastel1_r: colors.Colormap
193195
Pastel2_r: colors.Colormap

lib/matplotlib/colors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class ColorSequenceRegistry(Mapping):
128128
'Pastel2': _cm._Pastel2_data,
129129
'Paired': _cm._Paired_data,
130130
'Accent': _cm._Accent_data,
131+
'okabe_ito': _cm._okabe_ito_data,
131132
'Dark2': _cm._Dark2_data,
132133
'Set1': _cm._Set1_data,
133134
'Set2': _cm._Set2_data,

lib/matplotlib/tests/test_colors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,8 +1707,8 @@ def test_color_sequences():
17071707
assert plt.color_sequences is matplotlib.color_sequences # same registry
17081708
assert list(plt.color_sequences) == [
17091709
'tab10', 'tab20', 'tab20b', 'tab20c', 'Pastel1', 'Pastel2', 'Paired',
1710-
'Accent', 'Dark2', 'Set1', 'Set2', 'Set3', 'petroff6', 'petroff8',
1711-
'petroff10']
1710+
'Accent', 'okabe_ito', 'Dark2', 'Set1', 'Set2', 'Set3', 'petroff6',
1711+
'petroff8', 'petroff10']
17121712
assert len(plt.color_sequences['tab10']) == 10
17131713
assert len(plt.color_sequences['tab20']) == 20
17141714

0 commit comments

Comments
 (0)