32 lines
885 B
Python
32 lines
885 B
Python
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
|
|
# roll the die:
|
|
x1 = np.random.random_integers( 1, 6, 100 )
|
|
x2 = np.random.random_integers( 1, 6, 500 )
|
|
bins = np.arange(0.5, 7, 1.0)
|
|
|
|
plt.xkcd()
|
|
|
|
fig = plt.figure( figsize=(6,4) )
|
|
ax = fig.add_subplot( 1, 2, 1 )
|
|
ax.spines['right'].set_visible(False)
|
|
ax.spines['top'].set_visible(False)
|
|
ax.yaxis.set_ticks_position('left')
|
|
ax.xaxis.set_ticks_position('bottom')
|
|
ax.set_xlabel( 'x' )
|
|
ax.set_ylabel( 'Frequency' )
|
|
ax.hist([x2, x1], bins, color=['#FFCC00', '#FFFF66' ])
|
|
|
|
ax = fig.add_subplot( 1, 2, 2 )
|
|
ax.spines['right'].set_visible(False)
|
|
ax.spines['top'].set_visible(False)
|
|
ax.yaxis.set_ticks_position('left')
|
|
ax.xaxis.set_ticks_position('bottom')
|
|
ax.set_xlabel( 'x' )
|
|
ax.set_ylabel( 'Probability' )
|
|
ax.hist([x2, x1], bins, normed=True, color=['#FFCC00', '#FFFF66' ])
|
|
plt.tight_layout()
|
|
fig.savefig( 'diehistograms.pdf' )
|
|
#plt.show()
|