Matplotlib markers disappear when edgecolor = 'none'

…衆ロ難τιáo~ 提交于 2019-12-12 08:21: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.


回答1:


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.




回答2:


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.




回答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')


来源:https://stackoverflow.com/questions/10017876/matplotlib-markers-disappear-when-edgecolor-none

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!