Mike Dooley
Mike Dooley

Reputation: 966

How to update a matplotlib figure from loop?

the title says it.

I want to draw the evolution of a point cloud using matplotlib. Therefore I want to redraw the figure in the same window in every loop iteration without blocking the application.

Edit 1: pseudo snippet of my code

x,y = init_points()  // x,y are 2D coordinates

plt.ion()
plt.figure()
while transformation:
  x, y= transform(x,y)
  plt.plot(x, y)
  plt.draw()

Basically I managed to draw the points. But the new points are added to the old figure. I want to completely redraw the figure.

I think I need something similar to Matlab's hold on/ hold off

Upvotes: 1

Views: 346

Answers (1)

Booster
Booster

Reputation: 1669

This may help you:

plt.clf()

This clears the figure.

Upvotes: 3

Related Questions