Advertisement
Guest User

Untitled

a guest
Dec 21st, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import math
  4. import matplotlib.pyplot as plt
  5. import numpy as np
  6. from scipy.interpolate import spline
  7.  
  8. n = 60      # число открытых бочек
  9. p = 0.05    # вероятность выпадения леги
  10. q = 1 - p  
  11.  
  12. K = np.array([])
  13. P = np.array([])
  14.  
  15. for k in range(0, 11):
  16.     Pmn = math.factorial(n) / (math.factorial(k) * math.factorial(n-k)) * math.pow(p, k) * math.pow(q, n-k)
  17.     print(k, round(Pmn * 100, 3), "%")
  18.     K = np.append(K, k)
  19.     P = np.append(P, round(Pmn * 100, 3))
  20.  
  21. fig, ax = plt.subplots()
  22.  
  23. Knew = np.linspace(K.min(), K.max(), 100)
  24. Psmooth = spline(K,P,Knew)
  25.  
  26. ax.plot(Knew, Psmooth, lw=2, c="red")
  27. ax.plot(K, P, lw=0, c="red", aa=True, marker="o", ms=8)
  28. for i, txt in enumerate(P):
  29.     ax.annotate(txt, (K[i],P[i]))
  30. ax.grid(True)
  31.  
  32. fig.autofmt_xdate()
  33. plt.xticks(K)
  34. plt.title("The chance to get a few Legendaries from 60 barrels")
  35. plt.xlabel("The number of Legendaries")
  36. plt.ylabel("%")
  37. #plt.show()
  38.  
  39. fig.set_size_inches(16, 10)
  40. plt.savefig("bernulli_60_barrels.png", format='png', dpi=150)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement