Matplotlib markers disappear when edgecolor = 'none'

Go To StackoverFlow.com

20

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.

2012-04-04 19:22
by Mat Leonard
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, ...bernie 2012-04-04 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 2015-04-09 18:31


15

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.

2012-04-05 02:20
by Joe Kington


4

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.

2012-04-05 13:01
by bmu
What do you mean by self.colors[k]? When I run the similar code it says NameError: name 'self' is not defined - LWZ 2013-07-30 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 2013-07-30 05:55


3

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')
2016-11-16 11:54
by Gabriela Calvillo
Ads