Reputation: 127
I am using Pyplot in Python.
I know that you can pick and choose which points in particular you wish to remove, but this also affects the axis which I want to keep constant. Also, the points I generate are dynamically created (meaning I do not know what they are until they are actually made). Is there a method in a while I can basically wipe all the points of the graph but keep the same axis? I'd rather not have Python close the old window and create a new one.
Thanks for you help! Let me know what I need to clarify.
Upvotes: 0
Views: 10184
Reputation: 23145
I think you're looking for the clear method on the axis or the remove method on the PathCollection that is returned by the scatterplot. See also the discussion of the details in this answer. This is an example that keeps the axes and clears the points:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
paths = ax.scatter([3,2,1,4], [2,3,4,0])
paths.remove() # to just remove the scatter plot and keep the limits
Or:
ax.clear() # to clear the whole axes
edit: added example on how to just remove the points
Upvotes: 4
Reputation: 1686
Cant you retrieve the maximum and minimum limits through something like:
ymax,ymin = axes.get_ylim()
And then use that to re-initiate your new plot?
Upvotes: 0