9

It seems that now the default scatter plot marker is a filled circle without an edge. I want a marker with an edge and with facecolor="none". But if facecolor="none" but edgecolor is not specified, then the plot is empty. I want markers be in multiple distinct colors, but don't care which one has which color.

How can I just "turn on" the edges?

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
Hoseung Choi
  • 1,017
  • 2
  • 12
  • 20
  • hey, it seems that the provided answer does what you asked for. Would you please accept it by ticking the checkmark next to it? It makes it easier to find the solution. Thanks ! – Ciprian Tomoiagă Aug 26 '19 at 23:04

1 Answers1

14

There are two ways to produce empty or hollow scatter markers:

Setting facecolor to "none"

Instead of "just turning on" the edges, you may "turn off" the faces. So in order to make the facecolors of scatter markers transparent you may set the facecolor of the resulting PolyCollecton to "none".

sc = ax.scatter(...)
sc.set_facecolor("none")

This is different from sc = ax.scatter(x,y, c=x, facecolor="none"), because the c argument overwrites the facecolor.

Complete example:

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0,2*np.pi,20)
y = np.sin(x)

fig, ax=plt.subplots()
sc = ax.scatter(x,y, c=x, cmap="nipy_spectral")
sc.set_facecolor("none")

plt.show()

enter image description here

Using non-filled marker

A different option is to use a non-filled marker. This would have its facecolor only at the edge. An example may be marker="$\u25EF$" from the STIX font (also see this question)

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0,2*np.pi,20)
y = np.sin(x)

fig, ax=plt.subplots()

sc = ax.scatter(x,y, c=x, marker="$\u25EF$", cmap="nipy_spectral")

plt.show()

enter image description here

Note: In python 2, you would need to use marker=ur"$\u25EF$" instead.

Community
  • 1
  • 1
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
  • 1
    Thanks! however, the problem here is that there is no edge from the beginning. So whether the facecolor is overwritten or not, there is no edge left anyways. But the trick you showed will turn out to be very useful soon, I think. – Hoseung Choi Jul 22 '17 at 10:25
  • It's not clear to me what "there is no edge from the beginning" means. Do you get a different result when running the code from the first part of the solution here? – ImportanceOfBeingErnest Jul 22 '17 at 10:33