Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit029b026

Browse files
authored
Merge pull request#28796 from ammar-qazi/style_example
Add example of petroff10 in the style sheets to show how to use the color sequence.
2 parentse27961d +9159096 commit029b026

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
=====================
3+
Petroff10 style sheet
4+
=====================
5+
6+
This example demonstrates the "petroff10" style, which implements the 10-color
7+
sequence developed by Matthew A. Petroff [1]_ for accessible data visualization.
8+
The style balances aesthetics with accessibility considerations, making it
9+
suitable for various types of plots while ensuring readability and distinction
10+
between data series.
11+
12+
.. [1] https://arxiv.org/abs/2107.02270
13+
14+
"""
15+
16+
importmatplotlib.pyplotasplt
17+
importnumpyasnp
18+
19+
20+
defcolored_lines_example(ax):
21+
t=np.linspace(-10,10,100)
22+
nb_colors=len(plt.rcParams['axes.prop_cycle'])
23+
shifts=np.linspace(-5,5,nb_colors)
24+
amplitudes=np.linspace(1,1.5,nb_colors)
25+
fort0,ainzip(shifts,amplitudes):
26+
y=a/ (1+np.exp(-(t-t0)))
27+
line,=ax.plot(t,y,'-')
28+
point_indices=np.linspace(0,len(t)-1,20,dtype=int)
29+
ax.plot(t[point_indices],y[point_indices],'o',color=line.get_color())
30+
ax.set_xlim(-10,10)
31+
32+
33+
defimage_and_patch_example(ax):
34+
ax.imshow(np.random.random(size=(20,20)),interpolation='none')
35+
c=plt.Circle((5,5),radius=5,label='patch')
36+
ax.add_patch(c)
37+
38+
plt.style.use('petroff10')
39+
fig, (ax1,ax2)=plt.subplots(ncols=2,figsize=(12,5))
40+
fig.suptitle("'petroff10' style sheet")
41+
colored_lines_example(ax1)
42+
image_and_patch_example(ax2)
43+
plt.show()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp