import
matplotlib.pyplot as plt
import
numpy as np
from
scipy
import
stats
x
=
[
10
,
40
,
20
,
10
,
30
,
10
,
56
,
45
]
res
=
stats.cumfreq(x, numbins
=
4
,
defaultreallimits
=
(
1.5
,
5
))
rng
=
np.random.RandomState(seed
=
12345
)
samples
=
stats.norm.rvs(size
=
1000
,
random_state
=
rng)
res
=
stats.cumfreq(samples,
numbins
=
25
)
x
=
res.lowerlimit
+
np.linspace(
0
, res.binsize
*
res.cumcount.size,
res.cumcount.size)
fig
=
plt.figure(figsize
=
(
10
,
4
))
ax1
=
fig.add_subplot(
1
,
2
,
1
)
ax2
=
fig.add_subplot(
1
,
2
,
2
)
ax1.hist(samples, bins
=
25
,
color
=
"green"
)
ax1.set_title(
'Histogram'
)
ax2.bar(x, res.cumcount, width
=
4
, color
=
"blue"
)
ax2.set_title(
'Cumulative histogram'
)
ax2.set_xlim([x.
min
(), x.
max
()])
plt.show()