Using pyplot, I’ve created a figure and plotted a number of randomly scattered (x,y) points. I then want to connect some subset of these points with line segments. After the user presses a key, my program needs to then erase the previously drawn set of line segments (leaving the original points in place) and then draw new segments between another set of points.
My problem is that I don’t know how to erase the previous line segments. I tried re-plotting them in the background color (which is white) but this leaves a residue of non-white pixels where the line was. I can’t find any examples in the on-line documentation that does this. Is it possible and, if so, how?
Scipy has a tutorial for deleting a line from an axes. I use this in the following example, which I think emulates what you are trying to do: