Removing a point in a scatter plot using matplotlib

The code below creates a scatter plot with a white dot. How to remove this point without redrawing the entire figure?

g = Figure(figsize=(5,4), dpi=60);
b = g.add_subplot(111)
b.plot(x,y,'bo') # creates a blue dot
b.plot(x,y,'wo') # ovverrides the blue dot with a white dot (but the black circle around it remains)
+4
source share
1 answer

Overplotting is not the same as removal. With your second story call, you draw a white marker with a black border. You can set the edgecolor for the marker with plot(x,y,'wo', mec='w').

But if you really want to delete it, take the return line object and call its delete method.

fig, ax = plt.subplots(subplot_kw={'xlim': [0,1],
                                   'ylim': [0,1]})


p1, = ax.plot(0.5, 0.5, 'bo') # creates a blue dot
p2, = ax.plot(0.5, 0.5, 'ro')

p2.remove()

The above example leads to a figure with a blue marker. A red marker is added (in front), but is also deleted again.

+8

Source: https://habr.com/ru/post/1610379/


All Articles