Take the 2-minute tour ×

I'm working on a plot with translucent 'x' markers (20% alpha). How do I make the marker appear at 100% opacity in the legend?

import matplotlib.pyplot as plt
plt.plot_date( x = xaxis, y = yaxis, marker = 'x', color=[1, 0, 0, .2], label='Data Series' )
plt.legend(loc=3, mode="expand", numpoints=1, scatterpoints=1 )
share|improve this question
Really an interesting question, quite useful. Thanks! –  Pablo Navarro Oct 12 '12 at 13:38
add comment

1 Answer

up vote 1 down vote accepted

If you want to have something specific in your legend, it's easier to define objects that you place in the legend with appropriate text. For example:

import matplotlib.pyplot as plt
import pylab

line1 = pylab.Line2D(range(1),range(1),color='white',marker='x',markersize=10, markerfacecolor="red",alpha=1.0)
line2 = pylab.Line2D(range(10),range(10),marker="_",linewidth=3.0,color="dodgerblue",alpha=1.0)
plt.legend((line1,line2),('Text','Other Text'),numpoints=1,loc=1)

Here, line1 defines a short, white line (so essentially invisible) with the marker 'x' in red and full opacity. As an example, line2 gives you a longer blue line with no markers visible. By creating this "lines," you are able to more easily control their properties within the legend.

share|improve this answer
add comment

Your Answer


