[Matplotlib-users] Making a solid legend

Florian Lindner mailinglists at xgm.de
Thu Mar 23 09:24:31 EDT 2017


Hello,

I try to make the legend non-translucent, having a solid color and laying above the plot itself.

That's what I try:


import matplotlib.pyplot as plt

fig, ax1 = plt.subplots()
ax1.plot([0, 1], [0, 2], label = "Plot 1")

leg = ax1.legend(loc = 1)
leg.get_frame().set_facecolor("r")
leg.set_alpha(0)

plt.grid()
plt.show()


(you may have to pan the plot)

Taken from:
http://matplotlib.org/examples/api/legend_demo.html
http://matplotlib.org/1.3.0/examples/pylab_examples/legend_translucent.html

The set_alpha seems to have no effect at all. facecolor works, but it is always translucent.

Thanks,
Florian



More information about the Matplotlib-users mailing list