Skip to content

Add example of petroff10 in the style sheets to show how to use the color sequence. #28796

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 1 commit into from
Sep 11, 2024
Merged
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
43 changes: 43 additions & 0 deletions galleries/examples/style_sheets/petroff10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
=====================
Petroff10 style sheet
=====================

This example demonstrates the "petroff10" style, which implements the 10-color
sequence developed by Matthew A. Petroff [1]_ for accessible data visualization.
The style balances aesthetics with accessibility considerations, making it
suitable for various types of plots while ensuring readability and distinction
between data series.

.. [1] https://arxiv.org/abs/2107.02270

"""

import matplotlib.pyplot as plt
import numpy as np


def colored_lines_example(ax):
t = np.linspace(-10, 10, 100)
nb_colors = len(plt.rcParams['axes.prop_cycle'])
shifts = np.linspace(-5, 5, nb_colors)
amplitudes = np.linspace(1, 1.5, nb_colors)
for t0, a in zip(shifts, amplitudes):
y = a / (1 + np.exp(-(t - t0)))
line, = ax.plot(t, y, '-')
point_indices = np.linspace(0, len(t) - 1, 20, dtype=int)
ax.plot(t[point_indices], y[point_indices], 'o', color=line.get_color())
ax.set_xlim(-10, 10)


def image_and_patch_example(ax):
ax.imshow(np.random.random(size=(20, 20)), interpolation='none')
c = plt.Circle((5, 5), radius=5, label='patch')
ax.add_patch(c)

plt.style.use('petroff10')
fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(12, 5))
fig.suptitle("'petroff10' style sheet")
colored_lines_example(ax1)
image_and_patch_example(ax2)
plt.show()