3

I'm trying to plot a scatter plot with pandas api where each point is an empty circle, just with border color and transparency. I've tried a lot of tweaks in this code:

 ax = ddf.plot.scatter(
        x='espvida', 
        y='e_anosestudo', 
        c=ddf['cor'],
        alpha=.2,
        marker='o');

The generated plot looks like this:

Scatter plot

If you look closely at the points:

filled points

you'll see that they have a transparent fill color and a border. I'd like it to have just a transparent border. Hou would I do it?

neves
  • 33,186
  • 27
  • 159
  • 192

2 Answers2

3

I can't seem to get it to work with DataFrame.plot.scatter; it doesn't seem to respect the facecolors='none' kwarg, likely because some default color argument is being passed to plt.scatter.

Instead, fall back to matplotlib, specifying facecolors='none' and setting the edgecolors to the column in your df that represents the color.

Sample Data

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

df = pd.DataFrame({'x': np.random.normal(1,1,1000),
                   'y': np.random.normal(1,1,1000),
                   'color': list('rgby')*250})

plt.scatter(df.x.values, df.y.values, facecolors='none', edgecolors=df['color'], alpha=0.2, s=100)
plt.show()

enter image description here

ALollz
  • 57,915
  • 7
  • 66
  • 89
-1

From the matplotlib scatter doc:

edgecolors : color or sequence of color, optional, default: 'face'. The edge color of the marker. Possible values:

  • 'face': The edge color will always be the same as the face color.

  • 'none': No patch boundary will be drawn.

  • A matplotib color.

For non-filled markers, the edgecolors kwarg is ignored and forced to 'face' internally

Try add: edgecolors='none':

 ax = ddf.plot.scatter(
        x='espvida', 
        y='e_anosestudo', 
        c=ddf['cor'],
        alpha=.2,
        marker='o',
        edgecolors='none);
Community
  • 1
  • 1
Lucas
  • 6,869
  • 5
  • 29
  • 44