Plotting with a transparent marker but non-transparent edge

IanRoberts picture IanRoberts · May 11, 2014 · Viewed 40k times · Source

I'm trying to make a plot in matplotlib with transparent markers which have a fixed color edge . However, I can't seem to achieve a marker with transparent fill.

I have a minimum working example here:

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(10)
y1 = 2*x + 1
y2 = 3*x - 5

plt.plot(x,y1, 'o-', lw=6, ms=14)
plt.plot(x,y2, 'o', ms=14, markerfacecolor=None, alpha=0.5, markeredgecolor='red', markeredgewidth=5)

plt.show()

I tried two techniques I found online to achieve this: 1) Setting alpha parameter. However, this makes the marker edge transparent too, which is not the desired effect. 2) Setting markerfacecolor=None, although this has no effect on my plot

Is there a solution to this please?

Answer

Saullo G. P. Castro picture Saullo G. P. Castro · May 11, 2014

This is tricky in Matplotlib... you have to use a string "None" instead of the value None, then you can just do:

plt.plot(x,y2, 'o', ms=14, markerfacecolor="None",
         markeredgecolor='red', markeredgewidth=5)