File tree Expand file tree Collapse file tree 1 file changed +8
-7
lines changed
galleries/examples/statistics Expand file tree Collapse file tree 1 file changed +8
-7
lines changed Original file line number Diff line number Diff line change 20
20
import matplotlib .pyplot as plt
21
21
import numpy as np
22
22
23
- np .random .seed (19680801 )
23
+ rng = np .random .default_rng (19680801 )
24
24
25
25
# example data
26
- mu = 100 # mean of distribution
27
- sigma = 15 # standard deviation of distribution
28
- x = mu + sigma * np . random . randn ( 437 )
26
+ mu = 106 # mean of distribution
27
+ sigma = 17 # standard deviation of distribution
28
+ x = rng . normal ( loc = mu , scale = sigma , size = 420 )
29
29
30
- num_bins = 50
30
+ num_bins = 42
31
31
32
32
fig , ax = plt .subplots ()
33
33
38
38
y = ((1 / (np .sqrt (2 * np .pi ) * sigma )) *
39
39
np .exp (- 0.5 * (1 / sigma * (bins - mu ))** 2 ))
40
40
ax .plot (bins , y , '--' )
41
- ax .set_xlabel ('Smarts ' )
41
+ ax .set_xlabel ('Value ' )
42
42
ax .set_ylabel ('Probability density' )
43
- ax .set_title (r'Histogram of IQ: $\mu=100$, $\sigma=15$' )
43
+ ax .set_title ('Histogram of normal distribution sample: '
44
+ fr'$\mu={ mu :.0f} $, $\sigma={ sigma :.0f} $' )
44
45
45
46
# Tweak spacing to prevent clipping of ylabel
46
47
fig .tight_layout ()
You can’t perform that action at this time.
0 commit comments