This is similar to Matlab: Combine the legends of shaded error and solid line mean, except for Matplotlib. Example code:
import numpy as np
import matplotlib.pyplot as plt
x = np.array([0,1])
y = x + 1
f,a = plt.subplots()
a.fill_between(x,y+0.5,y-0.5,alpha=0.5,color='b')
a.plot(x,y,color='b',label='Stuff',linewidth=3)
a.legend()
plt.show()
The above code produces a legend that looks like this:
How can I create a legend entry that combines the shading from fill_between
and the line from plot
, so that it looks something like this (mockup made in Gimp):
linewidth=0
to thefill
makes this good enough, that removes the 'frame' from the legend entry. If you happen to know how to make the legend keys the same length, so the line fromplot
extends to the left/right edges of thefill
rectangle in the legend, that would be even better. – Connel