Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing a dot in a scatter plot with matplotlib

The below code creates a scatter plot with a white dot. How can I remove this dot without redrawing the whole 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)
like image 504
Nickpick Avatar asked Oct 06 '15 08:10

Nickpick


People also ask

How do you change the dot on a scatter plot?

On the Format tab, in the Current Selection group, click Format Selection. Click Marker Options, and then under Marker Type, make sure that Built-in is selected. In the Type box, select the marker type that you want to use.

How do I make the dots transparent in Matplotlib?

Adjust the Transparency of Scatter PointsUtilize the alpha argument in our scatter method and pass in a numeric value between 0 and 1. A value of 0 will make the plots fully transparent and unable to view on a white background. A value of 1 is the default with non-transparent points.

How do you change the shape of dots on a scatter plot in Python?

Just use the marker argument of the plot() function to custom the shape of the data points.


1 Answers

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

But if you really want to remove it, capture the returned line object, and call its remove 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 example above results in a figure with a blue marker. A red marker is added (in front) but also removed again.

like image 65
Rutger Kassies Avatar answered Nov 14 '22 22:11

Rutger Kassies