Skip to content

Commit 99ff693

Browse files
committed
DOC: fix stylesheet again
Co-authored by: David Stansby <dstansby@gmail.com>
1 parent 54cf7bc commit 99ff693

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

examples/style_sheets/style_sheets_reference.py

+16-22
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,13 @@ def plot_histograms(ax, prng, nb_samples=10000):
9898
return ax
9999

100100

101-
def plot_figure(style_label=""):
101+
def plot_figure(axs, style_label=""):
102102
"""Setup and plot the demonstration figure with a given style."""
103103
# Use a dedicated RandomState instance to draw the same "random" values
104104
# across the different figures.
105105
prng = np.random.RandomState(96917002)
106-
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-
113-
fig, axs = plt.subplots(ncols=6, nrows=1, num=style_label,
114-
figsize=fig_size, squeeze=True)
115-
axs[0].set_ylabel(style_label)
106+
axs[0].figure.set_facecolor(plt.rcParams['figure.facecolor'])
107+
axs[0].set_ylabel('ylabel')
116108

117109
plot_scatter(axs[0], prng)
118110
plot_image_and_patch(axs[1], prng)
@@ -121,23 +113,25 @@ def plot_figure(style_label=""):
121113
plot_colored_sinusoidal_lines(axs[4])
122114
plot_histograms(axs[5], prng)
123115

124-
fig.tight_layout()
125-
126-
return fig
127-
128116

129117
if __name__ == "__main__":
130118

131119
# Setup a list of all available styles, in alphabetical order but
132-
# the `default` and `classic` ones, which will be forced resp. in
133-
# first and second position.
120+
# the `default`, `classic`, which will be forced
121+
# resp. in first and second position.
134122
style_list = ['default', 'classic'] + sorted(
135-
style for style in plt.style.available if style != 'classic')
123+
style for style in plt.style.available if
124+
((style != 'classic') and (style[0] != '_')))
125+
nstyles = len(style_list)
136126

127+
fig = plt.figure(figsize=(7, nstyles*2), constrained_layout=True)
128+
subfigs = fig.subfigures(nstyles, 1)
137129
# Plot a demonstration figure for every available style sheet.
138-
for style_label in style_list:
130+
for sfig, style_label in zip(subfigs, style_list):
131+
139132
with plt.rc_context({"figure.max_open_warning": len(style_list)}):
140133
with plt.style.context(style_label):
141-
fig = plot_figure(style_label=style_label)
142-
143-
plt.show()
134+
ax = sfig.subplots(1, 6)
135+
plot_figure(ax, style_label=style_label)
136+
sfig.suptitle(style_label)
137+
plt.show()

0 commit comments

Comments
 (0)