I have the following plot in matplotlib:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Patch
x=np.linspace(0,2.,100)
y1=np.power(x,2)*2.+x
y2=np.power(x,2)*2-0.2
plt.plot(x,y1,color="k")
plt.plot(x,y2,color="k")
plt.fill_between(x,y1,y2,facecolor=(0,0,0,0.3),lw=0)
and I want to add a legend similar to this:
legend_elements = [Patch(facecolor=(0,0,0,0.4), edgecolor='k',
label='Filled area')]
plt.gca().legend(handles=legend_elements)
Which produces this:
However, I would like to remove the lateral edges from the patch in the legend, to match what I see in the plot (i.e., I only have the upper and lower edge).
I searched how to draw only some edges of a matplotlib patch but did not find anything. Is something like this possible at all?


