Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib markers disappear when edgecolor = 'none'

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.

like image 657
Mat Leonard Avatar asked Apr 04 '12 19:04

Mat Leonard


People also ask

How do I make markers transparent in MatPlotLib?

MatPlotLib with Python Create x_data and y_data(sin(x_data)), using numpy. Plot curve using x_data and y_data, with marker style and marker size. By changing the alpha, we can make it transparent to opaque. To get the essence of transparency (keeping alhpa value lesser), we can make grid lines, to see through.

What is the default marker in MatPlotLib?

Marker size is scaled by s and marker color is mapped to c . size in points^2. Default is rcParams['lines. markersize'] ** 2 .

Can marker be a list MatPlotLib?

It is currently not possible to supply a list of markers to the marker argument of scatter . Save this answer.

How do you change the color of a marker in Python?

All of the line properties can be controlled by keyword arguments. For example, you can set the color, marker, linestyle, and markercolor with: plot(x, y, color='green', linestyle='dashed', marker='o', markerfacecolor='blue', markersize=12).


3 Answers

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.

like image 161
Joe Kington Avatar answered Oct 11 '22 00:10

Joe Kington


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.

like image 20
bmu Avatar answered Oct 11 '22 00:10

bmu


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')
like image 20
Gabriela Calvillo Avatar answered Oct 11 '22 00:10

Gabriela Calvillo