0

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.

M2com
  • 127
  • 1
  • 9

2 Answers2

4

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

Community
  • 1
  • 1
SiggyF
  • 22,088
  • 8
  • 43
  • 57
0

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?

Henry
  • 1,646
  • 12
  • 28
  • Yes. I guess my confusion is actually re-initiating the new plot without closing and opening a new window each time. – M2com Sep 26 '15 at 21:07
  • You can use `plt.clf()` to clear the current figure without closing the window – Henry Sep 26 '15 at 21:13
  • The clf() worked really well. However I just need to restate what the the axis are, although this doesn't slow things down too much. Thanks! – M2com Sep 26 '15 at 21:33