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

Commitd9ef0a7

Browse files
authored
Merge pull request#21860 from timhoffm/doc-hide-internal-styles
DOC: Update style sheet reference
2 parents6a74631 +ad1b222 commitd9ef0a7

File tree

1 file changed

+31
-23
lines changed

1 file changed

+31
-23
lines changed

‎examples/style_sheets/style_sheets_reference.py‎

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
importnumpyasnp
1313
importmatplotlib.pyplotasplt
14+
importmatplotlib.colorsasmcolors
1415

1516
# Fixing random state for reproducibility
1617
np.random.seed(19680801)
@@ -26,15 +27,19 @@ def plot_scatter(ax, prng, nb_samples=100):
2627
returnax
2728

2829

29-
defplot_colored_sinusoidal_lines(ax):
30-
"""Plot sinusoidal lines with colors following the style color cycle."""
31-
L=2*np.pi
32-
x=np.linspace(0,L)
30+
defplot_colored_lines(ax):
31+
"""Plot lines with colors following the style color cycle."""
32+
t=np.linspace(-10,10,100)
33+
34+
defsigmoid(t,t0):
35+
return1/ (1+np.exp(-(t-t0)))
36+
3337
nb_colors=len(plt.rcParams['axes.prop_cycle'])
34-
shift=np.linspace(0,L,nb_colors,endpoint=False)
35-
forsinshift:
36-
ax.plot(x,np.sin(x+s),'-')
37-
ax.set_xlim([x[0],x[-1]])
38+
shifts=np.linspace(-5,5,nb_colors)
39+
amplitudes=np.linspace(1,1.5,nb_colors)
40+
fort0,ainzip(shifts,amplitudes):
41+
ax.plot(t,a*sigmoid(t,t0),'-')
42+
ax.set_xlim(-10,10)
3843
returnax
3944

4045

@@ -104,40 +109,43 @@ def plot_figure(style_label=""):
104109
# across the different figures.
105110
prng=np.random.RandomState(96917002)
106111

107-
# Tweak the figure size to be better suited for a row of numerous plots:
108-
# double the width and halve the height. NB: use relative changes because
109-
# some styles may have a figure size different from the default one.
110-
(fig_width,fig_height)=plt.rcParams['figure.figsize']
111-
fig_size= [fig_width*2,fig_height/2]
112-
113112
fig,axs=plt.subplots(ncols=6,nrows=1,num=style_label,
114-
figsize=fig_size,squeeze=True)
115-
axs[0].set_ylabel(style_label)
113+
figsize=(14.8,2.7),constrained_layout=True)
114+
115+
# make a suptitle, in the same style for all subfigures,
116+
# except those with dark backgrounds, which get a lighter color:
117+
background_color=mcolors.rgb_to_hsv(
118+
mcolors.to_rgb(plt.rcParams['figure.facecolor']))[2]
119+
ifbackground_color<0.5:
120+
title_color= [0.8,0.8,1]
121+
else:
122+
title_color=np.array([19,6,84])/256
123+
fig.suptitle(style_label,x=0.01,ha='left',color=title_color,
124+
fontsize=14,fontfamily='DejaVu Sans',fontweight='normal')
116125

117126
plot_scatter(axs[0],prng)
118127
plot_image_and_patch(axs[1],prng)
119128
plot_bar_graphs(axs[2],prng)
120129
plot_colored_circles(axs[3],prng)
121-
plot_colored_sinusoidal_lines(axs[4])
130+
plot_colored_lines(axs[4])
122131
plot_histograms(axs[5],prng)
123132

124-
fig.tight_layout()
125-
126-
returnfig
127-
128133

129134
if__name__=="__main__":
130135

131136
# Setup a list of all available styles, in alphabetical order but
132137
# the `default` and `classic` ones, which will be forced resp. in
133138
# first and second position.
139+
# styles with leading underscores are for internal use such as testing
140+
# and plot types gallery. These are excluded here.
134141
style_list= ['default','classic']+sorted(
135-
styleforstyleinplt.style.availableifstyle!='classic')
142+
styleforstyleinplt.style.available
143+
ifstyle!='classic'andnotstyle.startswith('_'))
136144

137145
# Plot a demonstration figure for every available style sheet.
138146
forstyle_labelinstyle_list:
139147
withplt.rc_context({"figure.max_open_warning":len(style_list)}):
140148
withplt.style.context(style_label):
141-
fig=plot_figure(style_label=style_label)
149+
plot_figure(style_label=style_label)
142150

143151
plt.show()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp