简体   繁体   中英

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

This may help you:

plt.clf()

This clears the figure.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM