12
12
import numpy as np
13
13
import matplotlib .pyplot as plt
14
14
import matplotlib .colors as mcolors
15
+ from matplotlib .patches import Rectangle
15
16
16
17
# Fixing random state for reproducibility
17
18
np .random .seed (19680801 )
@@ -65,8 +66,11 @@ def plot_colored_circles(ax, prng, nb_samples=15):
65
66
for sty_dict , j in zip (plt .rcParams ['axes.prop_cycle' ], range (nb_samples )):
66
67
ax .add_patch (plt .Circle (prng .normal (scale = 3 , size = 2 ),
67
68
radius = 1.0 , color = sty_dict ['color' ]))
68
- # Force the limits to be the same across the styles (because different
69
- # styles may have different numbers of available colors).
69
+ ax .grid (visible = True )
70
+
71
+ # Add title for enabling grid
72
+ plt .title ('ax.grid(True)' , family = 'monospace' , fontsize = 'small' )
73
+
70
74
ax .set_xlim ([- 4 , 8 ])
71
75
ax .set_ylim ([- 5 , 6 ])
72
76
ax .set_aspect ('equal' , adjustable = 'box' ) # to plot circles as circles
@@ -91,6 +95,7 @@ def plot_histograms(ax, prng, nb_samples=10000):
91
95
values = prng .beta (a , b , size = nb_samples )
92
96
ax .hist (values , histtype = "stepfilled" , bins = 30 ,
93
97
alpha = 0.8 , density = True )
98
+
94
99
# Add a small annotation.
95
100
ax .annotate ('Annotation' , xy = (0.25 , 4.25 ),
96
101
xytext = (0.9 , 0.9 ), textcoords = ax .transAxes ,
@@ -110,7 +115,7 @@ def plot_figure(style_label=""):
110
115
prng = np .random .RandomState (96917002 )
111
116
112
117
fig , axs = plt .subplots (ncols = 6 , nrows = 1 , num = style_label ,
113
- figsize = (14.8 , 2.7 ), constrained_layout = True )
118
+ figsize = (14.8 , 2.8 ), constrained_layout = True )
114
119
115
120
# make a suptitle, in the same style for all subfigures,
116
121
# except those with dark backgrounds, which get a lighter color:
@@ -126,10 +131,15 @@ def plot_figure(style_label=""):
126
131
plot_scatter (axs [0 ], prng )
127
132
plot_image_and_patch (axs [1 ], prng )
128
133
plot_bar_graphs (axs [2 ], prng )
129
- plot_colored_circles (axs [3 ], prng )
130
- plot_colored_lines (axs [4 ])
131
- plot_histograms (axs [5 ], prng )
134
+ plot_colored_lines (axs [3 ])
135
+ plot_histograms (axs [4 ], prng )
136
+ plot_colored_circles (axs [5 ], prng )
137
+
138
+ # add divider
139
+ rec = Rectangle ((1 + 0.025 , - 2 ), 0.05 , 16 ,
140
+ clip_on = False , color = 'gray' )
132
141
142
+ axs [4 ].add_artist (rec )
133
143
134
144
if __name__ == "__main__" :
135
145
0 commit comments