46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
import numpy as np
|
|
import scipy.stats as st
|
|
import matplotlib.pyplot as plt
|
|
import matplotlib.gridspec as gridspec
|
|
from plotstyle import *
|
|
|
|
if __name__ == "__main__":
|
|
# wikipedia:
|
|
# Generally, males vary in total length from 250 to 390 cm and
|
|
# weigh between 90 and 306 kg
|
|
n = 300
|
|
mu = 220.0
|
|
sigma = 40.0
|
|
rng = np.random.RandomState(32281)
|
|
indices = np.arange(n)
|
|
data = sigma*rng.randn(len(indices))+mu
|
|
|
|
fig = plt.figure()
|
|
spec = gridspec.GridSpec(nrows=1, ncols=2, width_ratios=[3, 1], wspace=0.08,
|
|
**adjust_fs(fig, left=6.0))
|
|
ax1 = fig.add_subplot(spec[0, 0])
|
|
ax1.plot(indices, data, **psAm)
|
|
ax1.set_xlabel('Index')
|
|
ax1.set_ylabel('Weight', 'kg')
|
|
ax1.set_xlim(-10, 310)
|
|
ax1.set_ylim(0, 370)
|
|
ax1.set_yticks(np.arange(0, 351, 100))
|
|
|
|
ax2 = fig.add_subplot(spec[0, 1])
|
|
xx = np.arange(0.0, 350.0, 0.5)
|
|
yy = st.norm.pdf(xx, mu, sigma)
|
|
ax2.plot(yy, xx, **lsBm)
|
|
bw = 20.0
|
|
h, b = np.histogram(data, np.arange(0, 401, bw))
|
|
ax2.barh(b[:-1], h/np.sum(h)/(b[1]-b[0]), height=bar_fac*bw, align='edge', **fsC)
|
|
ax2.set_xlabel('Pdf', '1/kg')
|
|
ax2.set_xlim(0, 0.012)
|
|
ax2.set_xticks([0, 0.005, 0.01])
|
|
ax2.set_xticklabels(['0', '0.005', '0.01'])
|
|
ax2.set_ylim(0, 370)
|
|
ax2.set_yticks(np.arange(0, 351, 100))
|
|
ax2.set_yticklabels([])
|
|
|
|
fig.savefig("normaldata.pdf")
|
|
plt.close()
|