This repository has been archived on 2021-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
scientificComputing/statistics/lecture/diehistograms.py

31 lines
814 B
Python

import numpy as np
import matplotlib.pyplot as plt
from plotstyle import *
# roll the die:
rng = np.random.RandomState(57281)
x1 = rng.random_integers(1, 6, 100)
x2 = rng.random_integers(1, 6, 500)
bins = np.arange(0.5, 7, 1.0)
fig, (ax1, ax2) = plt.subplots(1, 2)
fig.subplots_adjust(**adjust_fs(bottom=2.7, top=0.1))
ax1.set_xlim(0, 7)
ax1.set_xticks(range(1, 7))
ax1.set_xlabel('x')
ax1.set_ylim(0, 98)
ax1.set_ylabel('Frequency')
fs = fsC
fs['color'] = [fsC['facecolor'], fsE['facecolor']]
del fs['facecolor']
ax1.hist([x2, x1], bins, **fs)
ax2.set_xlim(0, 7)
ax2.set_xticks(range(1, 7))
ax2.set_xlabel('x')
ax2.set_ylim(0, 0.23)
ax2.set_ylabel('Probability')
ax2.plot([0.2, 6.8], [1.0/6.0, 1.0/6.0], zorder=1, **lsAm)
ax2.hist([x2, x1], bins, normed=True, zorder=10, **fs)
fig.savefig('diehistograms.pdf')