2323import matplotlib .pyplot as plt
2424import numpy as np
2525
26+ import matplotlib as mpl
2627import matplotlib .colors as mcolors
2728from matplotlib .patches import Rectangle
2829
@@ -47,7 +48,7 @@ def plot_colored_lines(ax):
4748 def sigmoid (t , t0 ):
4849 return 1 / (1 + np .exp (- (t - t0 )))
4950
50- nb_colors = len (plt .rcParams ['axes.prop_cycle' ])
51+ nb_colors = len (mpl .rcParams ['axes.prop_cycle' ])
5152 shifts = np .linspace (- 5 , 5 , nb_colors )
5253 amplitudes = np .linspace (1 , 1.5 , nb_colors )
5354 for t0 , a in zip (shifts , amplitudes ):
@@ -75,14 +76,15 @@ def plot_colored_circles(ax, prng, nb_samples=15):
7576 the color cycle, because different styles may have different numbers
7677 of colors.
7778 """
78- for sty_dict , j in zip (plt .rcParams ['axes.prop_cycle' ](),
79+ for sty_dict , j in zip (mpl .rcParams ['axes.prop_cycle' ](),
7980 range (nb_samples )):
8081 ax .add_patch (plt .Circle (prng .normal (scale = 3 , size = 2 ),
8182 radius = 1.0 , color = sty_dict ['color' ]))
8283 ax .grid (visible = True )
8384
8485 # Add title for enabling grid
85- plt .title ('ax.grid(True)' , family = 'monospace' , fontsize = 'small' )
86+ font_family = mpl .rcParams .get ('font.family' , 'monospace' )
87+ ax .set_title ('ax.grid(True)' , family = font_family , fontsize = 'medium' )
8688
8789 ax .set_xlim ([- 4 , 8 ])
8890 ax .set_ylim ([- 5 , 6 ])
@@ -133,11 +135,12 @@ def plot_figure(style_label=""):
133135 # make a suptitle, in the same style for all subfigures,
134136 # except those with dark backgrounds, which get a lighter color:
135137 background_color = mcolors .rgb_to_hsv (
136- mcolors .to_rgb (plt .rcParams ['figure.facecolor' ]))[2 ]
138+ mcolors .to_rgb (mpl .rcParams ['figure.facecolor' ]))[2 ]
137139 if background_color < 0.5 :
138140 title_color = [0.8 , 0.8 , 1 ]
139141 else :
140142 title_color = np .array ([19 , 6 , 84 ]) / 256
143+
141144 fig .suptitle (style_label , x = 0.01 , ha = 'left' , color = title_color ,
142145 fontsize = 14 , fontfamily = 'DejaVu Sans' , fontweight = 'normal' )
143146
@@ -147,28 +150,25 @@ def plot_figure(style_label=""):
147150 plot_colored_lines (axs [3 ])
148151 plot_histograms (axs [4 ], prng )
149152 plot_colored_circles (axs [5 ], prng )
150-
151153 # add divider
152154 rec = Rectangle ((1 + 0.025 , - 2 ), 0.05 , 16 ,
153155 clip_on = False , color = 'gray' )
154156
155157 axs [4 ].add_artist (rec )
156158
157- if __name__ == "__main__" :
158-
159- # Set up a list of all available styles, in alphabetical order but
160- # the `default` and `classic` ones, which will be forced resp. in
161- # first and second position.
162- # styles with leading underscores are for internal use such as testing
163- # and plot types gallery. These are excluded here.
164- style_list = ['default' , 'classic' ] + sorted (
165- style for style in plt .style .available
166- if style != 'classic' and not style .startswith ('_' ))
167-
168- # Plot a demonstration figure for every available style sheet.
169- for style_label in style_list :
170- with plt .rc_context ({"figure.max_open_warning" : len (style_list )}):
171- with plt .style .context (style_label ):
172- plot_figure (style_label = style_label )
173159
174- plt .show ()
160+ # Set up a list of all available styles, in alphabetical order but
161+ # the `default` and `classic` ones, which will be forced resp. in
162+ # first and second position.
163+ # styles with leading underscores are for internal use such as testing
164+ # and plot types gallery. These are excluded here.
165+ style_list = ['default' , 'classic' ] + sorted (
166+ style for style in mpl .style .available
167+ if style != 'classic' and not style .startswith ('_' ))
168+
169+ # Plot a demonstration figure for every available style sheet:
170+ for style_label in style_list :
171+ with mpl .rc_context ({"figure.max_open_warning" : len (style_list )}):
172+ with mpl .style .context (style_label , after_reset = True ):
173+ plot_figure (style_label = style_label )
174+ plt .show ()
0 commit comments