Guest User

Untitled

a guest
Nov 19th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib
  3. matplotlib.use("Agg")
  4. import matplotlib.pyplot as plt
  5. import matplotlib.animation as manimation
  6.  
  7. FFMpegWriter = manimation.writers['ffmpeg']
  8. writer = FFMpegWriter(fps=5)
  9.  
  10. fig = plt.figure(figsize=(12, 8))
  11.  
  12. bins = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9]).astype(float)
  13. centroids = (bins[1:] + bins[:-1]) / 2
  14.  
  15. counts = np.ones(8, dtype=float) * 100
  16. width = 0.9 * (bins[1] - bins[0])
  17. font = {'family': 'serif',
  18. 'color': 'navy',
  19. 'weight': 'bold',
  20. 'size': 20,
  21. }
  22.  
  23. with writer.saving(fig, "example.mp4", 100): # don't change this 100
  24. from tqdm import tqdm
  25. for i in tqdm(range(100)):
  26. plt.clf()
  27. plt.xlim(min(bins), max(bins))
  28. plt.ylim(50, 150)
  29. plt.gca().set_xticks(bins)
  30. plt.text(1, 140, f'iter={i + 1}', fontdict=font)
  31. counts += np.random.randint(-3, 4, size=8)
  32. plt.bar(centroids, counts, align='center', width=width, color='darkolivegreen')
  33. writer.grab_frame()
Add Comment
Please, Sign In to add comment