🌐 AI搜索 & 代理 主页
Skip to content
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
29 changes: 29 additions & 0 deletions doc/release/next_whats_new/okabe_ito_colormap.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Okabe-Ito accessible color sequence
-----------------------------------

Matplotlib now includes the `Okabe-Ito color sequence`_. Its colors remain distinguishable for common forms of color-vision deficiency and when printed.

.. _Okabe-Ito color sequence: https://jfly.uni-koeln.de/color/#pallet

For example, to set it as the default colormap for your plots and image-like artists, use:

.. code-block:: python

import matplotlib.pyplot as plt
from cycler import cycler

plt.rcParams['axes.prop_cycle'] = cycler('color', plt.colormaps['okabe_ito'].colors)
plt.rcParams['image.cmap'] = 'okabe_ito'

Or, when creating plots, you can pass it explicitly:

.. plot::

import matplotlib.pyplot as plt

colors = plt.colormaps['okabe_ito'].colors
x = range(5)
for i, c in enumerate(colors):
plt.plot(x, [v*(i+1) for v in x], color=c, label=f'line {i}')
plt.legend()
plt.show()
4 changes: 2 additions & 2 deletions galleries/examples/color/color_sequences.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def plot_color_sequences(names, ax):

built_in_color_sequences = [
'tab10', 'tab20', 'tab20b', 'tab20c', 'Pastel1', 'Pastel2', 'Paired',
'Accent', 'Dark2', 'Set1', 'Set2', 'Set3', 'petroff6', 'petroff8',
'petroff10']
'Accent', 'okabe_ito', 'Dark2', 'Set1', 'Set2', 'Set3', 'petroff6',
'petroff8', 'petroff10']


fig, ax = plt.subplots(figsize=(6.4, 9.6), layout='constrained')
Expand Down
2 changes: 1 addition & 1 deletion galleries/examples/color/colormap_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
'berlin', 'managua', 'vanimo']),
('Cyclic', ['twilight', 'twilight_shifted', 'hsv']),
('Qualitative', [
'Pastel1', 'Pastel2', 'Paired', 'Accent',
'Pastel1', 'Pastel2', 'Paired', 'Accent', 'okabe_ito',
'Dark2', 'Set1', 'Set2', 'Set3',
'tab10', 'tab20', 'tab20b', 'tab20c']),
('Miscellaneous', [
Expand Down
6 changes: 3 additions & 3 deletions galleries/users_explain/colors/colormaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ def plot_color_gradients(category, cmap_list):
# These would not be good options for use as perceptual colormaps.

plot_color_gradients('Qualitative',
['Pastel1', 'Pastel2', 'Paired', 'Accent', 'Dark2',
'Set1', 'Set2', 'Set3', 'tab10', 'tab20', 'tab20b',
'tab20c'])
['Pastel1', 'Pastel2', 'Paired', 'Accent', 'okabe_ito',
'Dark2', 'Set1', 'Set2', 'Set3', 'tab10', 'tab20',
'tab20b', 'tab20c'])

# %%
# Miscellaneous
Expand Down
18 changes: 17 additions & 1 deletion lib/matplotlib/_cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,6 @@ def _g36(x): return 2 * x - 1
(0.50196078431372548, 0.0 , 0.14901960784313725)
)


# ColorBrewer's qualitative maps, implemented using ListedColormap
# for use with mpl.colors.NoNorm

Expand All @@ -878,6 +877,22 @@ def _g36(x): return 2 * x - 1
(0.4, 0.4, 0.4 ),
)

# Okabe-Ito accessible and print-friendly color palette.
# By Masataka Okabe (Jikei Medical School) and Kei Ito (University of Tokyo).
# Qualitative color palette that is unambiguous regardless of whether
# the viewer has colorblindness. https://jfly.uni-koeln.de/color/#pallet

_okabe_ito_data = (
(0.0, 0.0, 0.0), # black
(0.9019607843137255, 0.6235294117647059, 0.0), # e69f00
(0.33725490196078434, 0.7058823529411765, 0.9137254901960784), # 56b4e9
(0.0, 0.6196078431372549, 0.45098039215686275), # 009e73
(0.9411764705882353, 0.8941176470588236, 0.25882352941176473), # f0e442
(0.0, 0.4470588235294118, 0.6980392156862745), # 0072b2
(0.8352941176470589, 0.3686274509803922, 0.0), # d55e00
(0.8, 0.4745098039215686, 0.6549019607843137), # cc79a7
)

_Paired_data = (
(0.65098039215686276, 0.80784313725490198, 0.8901960784313725 ),
(0.12156862745098039, 0.47058823529411764, 0.70588235294117652),
Expand Down Expand Up @@ -1469,6 +1484,7 @@ def _gist_yarg(x): return 1 - x
'winter': _winter_data,
# Qualitative
'Accent': {'listed': _Accent_data},
'okabe_ito': {'listed': _okabe_ito_data},
'Dark2': {'listed': _Dark2_data},
'Paired': {'listed': _Paired_data},
'Pastel1': {'listed': _Pastel1_data},
Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/cm.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ terrain: colors.Colormap
winter: colors.Colormap
Accent: colors.Colormap
Dark2: colors.Colormap
okabe_ito: colors.Colormap
Paired: colors.Colormap
Pastel1: colors.Colormap
Pastel2: colors.Colormap
Expand Down Expand Up @@ -188,6 +189,7 @@ terrain_r: colors.Colormap
winter_r: colors.Colormap
Accent_r: colors.Colormap
Dark2_r: colors.Colormap
okabe_ito_r: colors.Colormap
Paired_r: colors.Colormap
Pastel1_r: colors.Colormap
Pastel2_r: colors.Colormap
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class ColorSequenceRegistry(Mapping):
'Pastel2': _cm._Pastel2_data,
'Paired': _cm._Paired_data,
'Accent': _cm._Accent_data,
'okabe_ito': _cm._okabe_ito_data,
'Dark2': _cm._Dark2_data,
'Set1': _cm._Set1_data,
'Set2': _cm._Set2_data,
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1702,8 +1702,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', 'petroff6', 'petroff8',
'petroff10']
'Accent', 'okabe_ito', 'Dark2', 'Set1', 'Set2', 'Set3', 'petroff6',
'petroff8', 'petroff10']
assert len(plt.color_sequences['tab10']) == 10
assert len(plt.color_sequences['tab20']) == 20

Expand Down
Loading