Skip to content
Closed
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
21 changes: 6 additions & 15 deletions examples/style_sheets/style_sheets_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,12 @@ def plot_histograms(ax, prng, nb_samples=10000):
return ax


def plot_figure(style_label=""):
def plot_figure(axs, style_label=""):
"""Setup and plot the demonstration figure with a given style."""
# Use a dedicated RandomState instance to draw the same "random" values
# across the different figures.
prng = np.random.RandomState(96917002)

# Tweak the figure size to be better suited for a row of numerous plots:
# double the width and halve the height. NB: use relative changes because
# some styles may have a figure size different from the default one.
(fig_width, fig_height) = plt.rcParams['figure.figsize']
fig_size = [fig_width * 2, fig_height / 2]

fig, axs = plt.subplots(ncols=6, nrows=1, num=style_label,
figsize=fig_size, squeeze=True)
axs[0].set_ylabel(style_label)

plot_scatter(axs[0], prng)
Expand All @@ -121,10 +113,6 @@ def plot_figure(style_label=""):
plot_colored_sinusoidal_lines(axs[4])
plot_histograms(axs[5], prng)

fig.tight_layout()

return fig


if __name__ == "__main__":

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

fig, axs = plt.subplots(ncols=6, nrows=nstyles, figsize=(12, 3 * nstyles))
# Plot a demonstration figure for every available style sheet.
for style_label in style_list:
for axs_row, style_label in zip(axs, style_list):
with plt.rc_context({"figure.max_open_warning": len(style_list)}):
with plt.style.context(style_label):
fig = plot_figure(style_label=style_label)
plot_figure(axs_row, style_label=style_label)

fig.tight_layout()
plt.show()