4
4
The different plots are heavily similar to the other ones in the style sheet
5
5
gallery.
6
6
"""
7
+
7
8
import numpy as np
8
9
import matplotlib .pyplot as plt
9
10
@@ -13,14 +14,14 @@ def plot_scatter(ax, prng, nb_samples=100):
13
14
"""
14
15
for mu , sigma , marker in [(- .5 , 0.75 , 'o' ), (0.75 , 1. , 's' )]:
15
16
x , y = prng .normal (loc = mu , scale = sigma , size = (2 , nb_samples ))
16
- ax .plot (x , y , marker = marker , ls = '' )
17
+ ax .plot (x , y , ls = 'none' , marker = marker )
17
18
ax .set_xlabel ('X-label' )
18
19
ax .set_ylabel ('Y-label' )
19
20
return ax
20
21
21
22
22
23
def plot_colored_sinusoidal_lines (ax ):
23
- """ Plot sinusoidal lines with colors from default color cycle.
24
+ """ Plots sinusoidal lines with colors following the style color cycle.
24
25
"""
25
26
L = 2 * np .pi
26
27
x = np .linspace (0 , L )
@@ -33,7 +34,7 @@ def plot_colored_sinusoidal_lines(ax):
33
34
34
35
35
36
def plot_bar_graphs (ax , prng , min_value = 5 , max_value = 25 , nb_samples = 5 ):
36
- """ Plot two bar graphs side by side, with letters as xticklabels.
37
+ """ Plots two bar graphs side by side, with letters as xticklabels.
37
38
"""
38
39
x = np .arange (nb_samples )
39
40
ya , yb = prng .randint (min_value , max_value , size = (2 , nb_samples ))
@@ -46,11 +47,11 @@ def plot_bar_graphs(ax, prng, min_value=5, max_value=25, nb_samples=5):
46
47
47
48
48
49
def plot_colored_circles (ax , prng , nb_samples = 15 ):
49
- """ Plot circle patches.
50
+ """ Plots circle patches.
50
51
51
- NB: drawing a fixed amount of samples, rather than using the length of
52
- the color cycle, because different styles may have different numbers of
53
- colors.
52
+ NB: draws a fixed amount of samples, rather than using the length of
53
+ the color cycle, because different styles may have different numbers
54
+ of colors.
54
55
"""
55
56
for sty_dict , j in zip (plt .rcParams ['axes.prop_cycle' ], range (nb_samples )):
56
57
ax .add_patch (plt .Circle (prng .normal (scale = 3 , size = 2 ),
@@ -64,7 +65,7 @@ def plot_colored_circles(ax, prng, nb_samples=15):
64
65
65
66
66
67
def plot_image_and_patch (ax , prng , size = (20 , 20 )):
67
- """ Plot an image with random values and superimpose a circular patch.
68
+ """ Plots an image with random values and superimposes a circular patch.
68
69
"""
69
70
values = prng .random_sample (size = size )
70
71
ax .imshow (values , interpolation = 'none' )
@@ -73,15 +74,16 @@ def plot_image_and_patch(ax, prng, size=(20, 20)):
73
74
74
75
75
76
def plot_histograms (ax , prng , nb_samples = 10000 ):
76
- """ Plot 4 histograms and a text annotation.
77
+ """ Plots 4 histograms and a text annotation.
77
78
"""
78
79
params = ((10 , 10 ), (4 , 12 ), (50 , 12 ), (6 , 55 ))
79
80
for a , b in params :
80
81
values = prng .beta (a , b , size = nb_samples )
81
82
ax .hist (values , histtype = "stepfilled" , bins = 30 , alpha = 0.8 , normed = True )
82
83
# Add a small annotation.
83
84
ax .annotate ('Annotation' , xy = (0.25 , 4.25 ), xycoords = 'data' ,
84
- xytext = (0.4 , 10 ), textcoords = 'data' ,
85
+ xytext = (0.9 , 0.9 ), textcoords = 'axes fraction' ,
86
+ va = "top" , ha = "right" ,
85
87
bbox = dict (boxstyle = "round" , alpha = 0.2 ),
86
88
arrowprops = dict (
87
89
arrowstyle = "->" ,
@@ -92,7 +94,7 @@ def plot_histograms(ax, prng, nb_samples=10000):
92
94
93
95
def plot_figure (style_label = None ):
94
96
"""
95
- Setup and plot the demonstration figure with the style `style_label`.
97
+ Sets up and plots the demonstration figure with the style `style_label`.
96
98
If `style_label` is None, fall back to the `default` style.
97
99
"""
98
100
if style_label is None :
@@ -112,6 +114,8 @@ def plot_figure(style_label=None):
112
114
plot_colored_sinusoidal_lines (axes [1 , 1 ])
113
115
plot_histograms (axes [1 , 2 ], prng )
114
116
117
+ fig .tight_layout ()
118
+
115
119
return fig
116
120
117
121
0 commit comments