Няма описание

rw_visual.py 937B

1234567891011121314151617181920212223242526272829303132
  1. import matplotlib.pyplot as plt
  2. from random_walk import RandomWalk
  3. # Keep making new walks, as long as the program is active.
  4. while True:
  5. # Make a random walk, and plot the points.
  6. rw = RandomWalk(50000)
  7. rw.fill_walk()
  8. # Set the size of the plotting window.
  9. plt.figure(dpi=128, figsize=(10, 6))
  10. point_numbers = list(range(rw.num_points))
  11. plt.scatter(rw.x_values, rw.y_values, c=point_numbers, cmap=plt.cm.Blues,
  12. edgecolor='none', s=1)
  13. # Emphasize the first and last points.
  14. plt.scatter(0, 0, c='green', edgecolors='none', s=100)
  15. plt.scatter(rw.x_values[-1], rw.y_values[-1], c='red', edgecolors='none',
  16. s=100)
  17. # Remove the axes.
  18. plt.axes().get_xaxis().set_visible(False)
  19. plt.axes().get_yaxis().set_visible(False)
  20. plt.show()
  21. keep_running = input("Make another walk? (y/n): ")
  22. if keep_running == 'n':
  23. break