23

I'm trying to make a scatter plot of some PCA data. I do some pretty typical code:

plt.plot(pca[:,0], pca[:,1], '.',ms=3,  markerfacecolor = self.colors[k],
            markeredgecolor = 'none')

I want it to show just the marker face color with no outline. The problem is that the markers disappear completely when markeredgecolor = 'none'. When I set markerfacecolor='none' or to a color and remove markeredgecolor, it works like expected.

I just updated matplotlib, numpy, etc. to the newest versions, running on Python 2.7.

Thanks for your help.

mechanical_meat
  • 163,903
  • 24
  • 228
  • 223
Mat Leonard
  • 253
  • 1
  • 2
  • 6
  • 3
    You might try setting the `markersize` to a larger value. `markersize` can be a kwarg to `plot()`, or you can abbreviate as `ms`. e.g.: `..., markersize=20, ...` – mechanical_meat Apr 04 '12 at 19:33
  • For those trying to do this with `matplotlib.errorbar` using the `markeredgecolor=None` recommended below did not remove the black outlining the symbol. Instead `markeredgecolor='none'`did work (the symbols were not invisible). Not surprisingly, it seems the bug that led to this question has been fixed in the past 3 years. – Steven C. Howell Apr 09 '15 at 18:31

3 Answers3

20

I think this is a bug that was fixed a few months ago: https://github.com/matplotlib/matplotlib/pull/598

Regardless of how large you make the markers or if you use marker='o' instead of '.', they'll be invisible if you use markeredgecolor='none'.

As a workaround, you can just set the edge colors to the same as the face colors.

Joe Kington
  • 275,208
  • 71
  • 604
  • 463
7

In matplotlib 1.1

>> plt.plot(pca[:,0], pca[:,1], '.', ms=3, markerfacecolor=self.colors[k],
...          markeredgecolor=None)

works (note the None instead of 'none' for markeredgecolor).

Setting markeredgewidth=0.0 or markeredgecolor=self.colors[k] (as suggested by Joe Kington) should work, too.

bmu
  • 35,119
  • 13
  • 91
  • 108
  • What do you mean by `self.colors[k]`? When I run the similar code it says `NameError: name 'self' is not defined`. – LWZ Jul 30 '13 at 04:14
  • It is taken from the question. Seems like the the OP is using this command from within a class, which has a colors attribute (which is a dictionary). You can replace it by any matplotlib color (e.g. a string like 'green') if you just want to use the code line to plot something. – bmu Jul 30 '13 at 05:55
  • As of now (newer matplotlib), should use `markedgecolor="None"`, see this [answer](https://stackoverflow.com/a/23596637/10039621). – Gordon Bai Jun 25 '21 at 20:41
5

Try this:

x = np.array(np.random.rand(10))
y = np.array(np.random.rand(10))
c = np.arange(len(x))
plt.scatter(x,y, c=c, s=500, cmap = plt.cm.Paired, alpha = 0.5,linewidths=0)

Or, this is a good option too:

plt.scatter(x,y, c=c, s=500, cmap = plt.cm.Paired, alpha = 0.5,edgecolor='face')