Removing previously plotted points on scatter plot; python

Click For Summary
SUMMARY

The discussion focuses on dynamically plotting moving particles using Python's Matplotlib library, specifically in a Jupyter Notebook environment. The user seeks to refresh the graph space in each iteration to prevent old points from leaving a trail. The provided solution involves using a loop with plt.scatter and adjusting the limits with plt.xlim and plt.ylim. The mentor suggests considering refresh rates to ensure points are displayed correctly without flickering.

PREREQUISITES
  • Proficiency in Python programming
  • Familiarity with Matplotlib 3.x for plotting
  • Understanding of Jupyter Notebook for interactive plotting
  • Basic knowledge of particle simulation concepts
NEXT STEPS
  • Explore Matplotlib's animation API for smoother visualizations
  • Learn about using FuncAnimation for dynamic updates in plots
  • Investigate refresh rate optimization techniques in Jupyter Notebooks
  • Study examples of real-time data visualization with Matplotlib
USEFUL FOR

This discussion is beneficial for data scientists, Python developers, and anyone interested in real-time data visualization using Matplotlib in Jupyter Notebooks.

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:
Technology news on Phys.org

Similar threads

  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
Replies
4
Views
5K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 21 ·
Replies
21
Views
6K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
11K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
2
Views
2K