5

I would like to plot a scatter plot by using 2 indexes [ChildrenHeight, ParentHeight] for a categorical variable: [gender]. However, I have tired many approaches to draw a empty circle with distinct edgecolors.

I have tried:

plt.scatter(X[:, 0], X[:, 1], c=y, marker = 'o',facecolors='none', cmap=plt.cm.Set1)

but it just gave me full circles:

enter image description here

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
Qing
  • 51
  • 1
  • 1
  • 5

1 Answers1

5

Don't use cmap in that way, try fillstyle = 'none' command : https://matplotlib.org/gallery/lines_bars_and_markers/marker_fillstyle_reference.html

For example,

x = np.random.randint(100, size=100)
y = np.random.randint(100, size=100)

plt.plot(x,y,lw=0, marker='o', fillstyle='none')

plt.show()

enter image description here

Or, if you want tu use plt.scatter:

plt.scatter(x,y,marker='o', facecolors='none', edgecolors='r')

plt.show()

enter image description here

Alessandro Peca
  • 873
  • 1
  • 15
  • 40
  • Thank you! But when I tried: `plt.scatter(X[:, 0], X[:, 1], c=y,marker='o', facecolors='none', edgecolors='r')` It seems that facecolors doesn't work. The color inside the circle still appears – Qing Mar 25 '18 at 17:03
  • Because the y variable is a categorical value with 0 and 1 and I have to plot these two with different colors – Qing Mar 25 '18 at 17:05
  • Try to cancel `c=y` and try to use `edgecolors=y`, where `y` are different colors. You can store them in an array under a `if` condition, something like `if y=1 -> color = red; else -> color=gray`. – Alessandro Peca Mar 25 '18 at 17:30