Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

test_plot2.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import time
  2. import matplotlib
  3. import numpy as np
  4. # matplotlib.use('GTK3Agg')
  5. from matplotlib import pyplot as plt
  6. def randomwalk(dims=(256, 256), n=20, sigma=5, alpha=0.95, seed=1):
  7. """ A simple random walk with memory """
  8. r, c = dims
  9. gen = np.random.RandomState(seed)
  10. pos = gen.rand(2, n) * ((r,), (c,))
  11. old_delta = gen.randn(2, n) * sigma
  12. while True:
  13. delta = (1. - alpha) * gen.randn(2, n) * sigma + alpha * old_delta
  14. pos += delta
  15. for ii in xrange(n):
  16. if not (0. <= pos[0, ii] < r):
  17. pos[0, ii] = abs(pos[0, ii] % r)
  18. if not (0. <= pos[1, ii] < c):
  19. pos[1, ii] = abs(pos[1, ii] % c)
  20. old_delta = delta
  21. yield pos
  22. def run(niter=1000, doblit=True):
  23. """
  24. Display the simulation using matplotlib, optionally using blit for speed
  25. """
  26. fig, ax = plt.subplots(1, 1)
  27. ax.set_aspect('equal')
  28. ax.set_xlim(0, 255)
  29. ax.set_ylim(0, 255)
  30. # ax.hold(True)
  31. rw = randomwalk()
  32. # x, y = rw.next()
  33. x, y = 0,0
  34. plt.show(False)
  35. plt.draw()
  36. fig.canvas.mpl_connect('draw_event', sentinel)
  37. # fig.canvas.draw()
  38. if doblit:
  39. # cache the background
  40. background = fig.canvas.copy_from_bbox(ax.bbox)
  41. points = ax.plot(x, y, 'o')[0]
  42. tic = time.time()
  43. for ii in range(niter):
  44. # update the xy data
  45. # x, y = rw.next()
  46. x,y = 0,0
  47. points.set_data(x, y)
  48. if doblit:
  49. # restore background
  50. fig.canvas.restore_region(background)
  51. # redraw just the points
  52. ax.draw_artist(points)
  53. # fill in the axes rectangle
  54. fig.canvas.blit(ax.bbox)
  55. else:
  56. # redraw everything
  57. fig.canvas.draw()
  58. plt.close(fig)
  59. print("Blit = %s, average FPS: %.2f" % (str(doblit), niter / (time.time() - tic)))
  60. def sentinel(event):
  61. state['draw'] = True
  62. if __name__ == '__main__':
  63. # run(doblit=False)
  64. state = {'draw': False}
  65. run(doblit=True)