Skip to content

Commit ad1b222

Browse files
committed
Fix the figure size in style sheet reference
It's better to override absolute sizes in the style sheet. Otherwise, larger figure images are scaled down due to the limited available width in the html theme. If not, we still don't get a size relation, but we also have different magnifications due to the image scaling. Notes: - The width (7.4 -> 740px, assuming 100 dpi) is chosen to fit in the HTML without scaling. - The size is chosen to approximately keep the aspect ratio as before. - The images are now significantly smaller than previously (all former images were downscaled). We'll have to verify that the images still look good given a lot of information and not much space. If not, we need to add a factor. - All themes use figure.dpi=100, except "classic", which uses 80. Not correcting for that is intentional. IMHO "classic" should come out smaller to highlight the change in dpi.
1 parent b371463 commit ad1b222

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

examples/style_sheets/style_sheets_reference.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,26 +109,19 @@ def plot_figure(style_label=""):
109109
# across the different figures.
110110
prng = np.random.RandomState(96917002)
111111

112-
# Tweak the figure size to be better suited for a row of numerous plots:
113-
# double the width and halve the height. NB: use relative changes because
114-
# some styles may have a figure size different from the default one.
115-
(fig_width, fig_height) = plt.rcParams['figure.figsize']
116-
fig_size = [fig_width * 2, fig_height / 1.75]
117-
118112
fig, axs = plt.subplots(ncols=6, nrows=1, num=style_label,
119-
figsize=fig_size, constrained_layout=True)
113+
figsize=(14.8, 2.7), constrained_layout=True)
120114

121115
# make a suptitle, in the same style for all subfigures,
122-
# except those with dark backgrounds, which get a lighter
123-
# color:
124-
col = np.array([19, 6, 84])/256
125-
back = mcolors.rgb_to_hsv(
116+
# except those with dark backgrounds, which get a lighter color:
117+
background_color = mcolors.rgb_to_hsv(
126118
mcolors.to_rgb(plt.rcParams['figure.facecolor']))[2]
127-
if back < 0.5:
128-
col = [0.8, 0.8, 1]
129-
fig.suptitle(style_label, x=0.01, fontsize=14, ha='left',
130-
color=col, fontfamily='DejaVu Sans',
131-
fontweight='normal')
119+
if background_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')
132125

133126
plot_scatter(axs[0], prng)
134127
plot_image_and_patch(axs[1], prng)

0 commit comments

Comments
 (0)