Skip to content

Instantly share code, notes, and snippets.

@galenseilis
Created October 16, 2022 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save galenseilis/acafeb29fa6ca0334228b6efad9a2334 to your computer and use it in GitHub Desktop.
Save galenseilis/acafeb29fa6ca0334228b6efad9a2334 to your computer and use it in GitHub Desktop.
import matplotlib.gridspec as gridspec
import matplotlib.pyplot as plt
import numpy as np
gs = gridspec.GridSpec(4, 4)
x = np.random.randint(1,7,size=10**5)
n, c = np.unique(x, return_counts=True)
ax1 = plt.subplot(gs[:2, :2])
ax1.bar(n, c)
ax1.set_title('Rolling one die')
ax1.set_xlabel('Total')
ax1.set_ylabel('Frequency')
x = np.random.randint(1,7,size=10**5 * 2).reshape(10**5, 2)
x = np.sum(x, axis=1)
n, c = np.unique(x, return_counts=True)
ax2 = plt.subplot(gs[:2, 2:])
ax2.bar(n, c)
ax2.set_title('Rolling two dice')
ax2.set_xlabel('Total')
ax2.set_ylabel('Frequency')
x = np.random.randint(1,7,size=10**5 * 100).reshape(10**5, 100)
x = np.sum(x, axis=1)
n, c = np.unique(x, return_counts=True)
ax3 = plt.subplot(gs[2:4, 1:3])
ax3.plot(n, c)
ax3.set_title('Rolling one hundred dice')
ax3.set_xlabel('Total')
ax3.set_ylabel('Frequency')
plt.tight_layout()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment