Legend with transparent frame and non-transparent edge
11,324
Unfortunately, the framealpha
overrides the alpha value of the actual edge- or facecolors. Hence one would need to set the color, including alpha, manually on the legend patch.
legend = plt.legend(loc="upper right", edgecolor="black")
legend.get_frame().set_alpha(None)
legend.get_frame().set_facecolor((0, 0, 1, 0.1))
Author by
EternalGenin
Updated on June 07, 2022Comments
-
EternalGenin almost 2 years
When setting the transparency in a legend:
plt.legend(framealpha=0.5)
it affects both the background and the edge. How can I apply transparency only to the background and not to the edge?
I have tried:
plt.legend(edgecolor=(0, 0, 0, 1.), facecolor=(1, 1, 1, 0.1))
with which I can change the color but not the transparency, i.e., using
facecolor=(1, 0, 0, 0.1)
does change the background color to red but usingfacecolor=(1, 0, 0, 0.5)
doesn't make any difference in transparency.I'm using matplotlib v3.1.1.