Skip to content

Commit 6b1c484

Browse files
committed
Use a single figure for style sheet example
1 parent 25a54a4 commit 6b1c484

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

examples/style_sheets/style_sheets_reference.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,12 @@ 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)
106106

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)
115107
axs[0].set_ylabel(style_label)
116108

117109
plot_scatter(axs[0], prng)
@@ -121,10 +113,6 @@ 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

@@ -133,11 +121,14 @@ def plot_figure(style_label=""):
133121
# first and second position.
134122
style_list = ['default', 'classic'] + sorted(
135123
style for style in plt.style.available if style != 'classic')
124+
nstyles = len(style_list)
136125

126+
fig, axs = plt.subplots(ncols=6, nrows=nstyles, figsize=(12, 3 * nstyles))
137127
# Plot a demonstration figure for every available style sheet.
138-
for style_label in style_list:
128+
for axs_row, style_label in zip(axs, style_list):
139129
with plt.rc_context({"figure.max_open_warning": len(style_list)}):
140130
with plt.style.context(style_label):
141-
fig = plot_figure(style_label=style_label)
131+
plot_figure(axs_row, style_label=style_label)
142132

133+
fig.tight_layout()
143134
plt.show()

0 commit comments

Comments
 (0)