Removing previously plotted points on scatter plot; python

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 11K views
Morbidly_Green
Messages
12
Reaction score
0

Homework Statement


I'm plotting moving particles and I need a way to refresh the graph space with every loop. Meaning I want the points to NOT leave a trail of other points behind them . Basically I want to get rid of the old points as I plot new ones.

Homework Equations


N\A

The Attempt at a Solution


The code for plotting that is being used :
Python:
while True:

    plt.ion()
    plt.show()

    x,y = 0,0

    for i in range(n_particles):
        x = particle_pos[i,0]
        y = particle_pos[i,1]
        plt.scatter(x,y, color='green')
        plt.pause(0.001)
        plt.xlim(0 , L)
        plt.ylim(0 , L)

Mentor edit - added code tags.
 
Last edited by a moderator:
Physics news on Phys.org