FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
matplotlib.github.com/1.2.1/users/recipes-5.py at main · matplotlib/matplotlib.github.com · GitHub
matplotlib
/
matplotlib.github.com
Public
Notifications
You must be signed in to change notification settings
Fork
62
Star
29
Code
Issues
1
Pull requests
2
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
matplotlib.github.com
/
1.2.1
/
users
/
recipes-5.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
33 lines (27 loc) · 1 KB
Breadcrumbs
matplotlib.github.com
/
1.2.1
/
users
/
recipes-5.py
Copy path
File metadata and controls
33 lines (27 loc) · 1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import
matplotlib
.
pyplot
as
plt
import
numpy
as
np
Nsteps
,
Nwalkers
=
100
,
250
t
=
np
.
arange
(
Nsteps
)
# an (Nsteps x Nwalkers) array of random walk steps
S1
=
0.002
+
0.01
*
np
.
random
.
randn
(
Nsteps
,
Nwalkers
)
S2
=
0.004
+
0.02
*
np
.
random
.
randn
(
Nsteps
,
Nwalkers
)
# an (Nsteps x Nwalkers) array of random walker positions
X1
=
S1
.
cumsum
(
axis
=
0
)
X2
=
S2
.
cumsum
(
axis
=
0
)
# Nsteps length arrays empirical means and standard deviations of both
# populations over time
mu1
=
X1
.
mean
(
axis
=
1
)
sigma1
=
X1
.
std
(
axis
=
1
)
mu2
=
X2
.
mean
(
axis
=
1
)
sigma2
=
X2
.
std
(
axis
=
1
)
# plot it!
fig
,
ax
=
plt
.
subplots
(
1
)
ax
.
plot
(
t
,
mu1
,
lw
=
2
,
label
=
'mean population 1'
,
color
=
'blue'
)
ax
.
plot
(
t
,
mu1
,
lw
=
2
,
label
=
'mean population 2'
,
color
=
'yellow'
)
ax
.
fill_between
(
t
,
mu1
+
sigma1
,
mu1
-
sigma1
,
facecolor
=
'blue'
,
alpha
=
0.5
)
ax
.
fill_between
(
t
,
mu2
+
sigma2
,
mu2
-
sigma2
,
facecolor
=
'yellow'
,
alpha
=
0.5
)
ax
.
set_title
(
'random walkers empirical $\mu$ and $\pm \sigma$ interval'
)
ax
.
legend
(
loc
=
'upper left'
)
ax
.
set_xlabel
(
'num steps'
)
ax
.
set_ylabel
(
'position'
)
ax
.
grid
()
Back
|
FazBrowse Home
|
New Git URL