Removing previously plotted points on scatter plot; python

In summary, the conversation discusses the need to refresh the graph space with every loop while plotting moving particles. This means getting rid of old points and plotting new ones without leaving a trail behind. The code being used involves using matplotlib in Jupyter and considering timing for proper visualization. Additional links are provided for further assistance.
  • #1
Morbidly_Green
12
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

1. How do I remove previously plotted points on a scatter plot in Python?

To remove previously plotted points on a scatter plot in Python, you can use the plt.cla() function. This function clears the current axes and allows you to plot new points on the same graph.

2. Can I remove specific points from a scatter plot in Python?

Yes, you can remove specific points from a scatter plot in Python by using the plt.scatter() function with the marker='none' argument. This will plot the points without any markers, effectively removing them from the plot.

3. How do I remove all the points from a scatter plot in Python?

To remove all the points from a scatter plot in Python, you can use the plt.clf() function. This function clears the entire figure, including all axes and any plotted points.

4. Is there a way to undo the removal of points on a scatter plot in Python?

Unfortunately, there is no built-in way to undo the removal of points on a scatter plot in Python. However, you can save your plot before removing the points, and then re-plot the original data if needed.

5. Can I remove previously plotted points on a scatter plot using a specific condition?

Yes, you can remove previously plotted points on a scatter plot using a specific condition by first creating a filter for the data points you want to remove, and then using the plt.scatter() function with the filtered data. This will only plot the data points that meet your specified condition on the scatter plot.

Similar threads

  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
1
Views
587
  • Programming and Computer Science
Replies
21
Views
4K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
1
Views
9K
  • Programming and Computer Science
Replies
3
Views
855
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
4
Views
5K
Back
Top