@@ -98,21 +98,13 @@ def plot_histograms(ax, prng, nb_samples=10000):
98
98
return ax
99
99
100
100
101
- def plot_figure (style_label = "" ):
101
+ def plot_figure (axs , style_label = "" ):
102
102
"""Setup and plot the demonstration figure with a given style."""
103
103
# Use a dedicated RandomState instance to draw the same "random" values
104
104
# across the different figures.
105
105
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' )
116
108
117
109
plot_scatter (axs [0 ], prng )
118
110
plot_image_and_patch (axs [1 ], prng )
@@ -121,23 +113,25 @@ def plot_figure(style_label=""):
121
113
plot_colored_sinusoidal_lines (axs [4 ])
122
114
plot_histograms (axs [5 ], prng )
123
115
124
- fig .tight_layout ()
125
-
126
- return fig
127
-
128
116
129
117
if __name__ == "__main__" :
130
118
131
119
# 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.
134
122
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 )
136
126
127
+ fig = plt .figure (figsize = (7 , nstyles * 2 ), constrained_layout = True )
128
+ subfigs = fig .subfigures (nstyles , 1 )
137
129
# 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
+
139
132
with plt .rc_context ({"figure.max_open_warning" : len (style_list )}):
140
133
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