[Matplotlib-users] Making a solid legend
mailinglists at xgm.de
Thu Mar 23 10:10:25 EDT 2017
Am 23.03.2017 um 14:38 schrieb vincent.adrien at gmail.com:
> Hello Florian,
> A `get_frame()` call seems to be missing in your example. Try with
> Note that you can also directly set this when calling `legend`:
> import matplotlib.pyplot as plt
> fig, ax = plt.subplots()
> ax.plot([0, 1], label='Plot 1')
> leg = ax.legend(loc='upper left', framealpha=1.0, facecolor='red')
> If you want to fix this for every plot you do, you may want to tweak your
> matplotlibrc file or at least the related rcParams in your scrpit, which are
> 'legend.framecolor' and 'legend.framealpha'.
Oh, cool, that is what I was looking for too.
I found out that my original issue is also related to twinx:
import matplotlib.pyplot as plt
fig, ax1 = plt.subplots()
ax1.plot([0, 1], [0, 2], label = "Plot 1 with some more text")
ax1.legend(framealpha = 1, bbox_to_anchor = (0.1, 1))
ax2 = ax1.twinx()
ax2.plot([0, 1], [2.2, 0], "--", label = "Plot 2 with some more text")
ax2.legend(framealpha = 1, bbox_to_anchor = (1.1,1))
The second legend is over the right y-axis, the first legend is not over the left y-axis.
Can I set legends in a way they are always above any element?
> Best regards,
> On 23/03/2017 14:24, Florian Lindner wrote:
>> 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)
>> (you may have to pan the plot)
>> Taken from:
>> The set_alpha seems to have no effect at all. facecolor works, but it is always translucent.
>> Matplotlib-users mailing list
>> Matplotlib-users at python.org
More information about the Matplotlib-users