Hi I am using fill_between command in python, but it seems that the fill_between is always below the line plots.
See this example, the alpha=1, so it is not invisible. All the lines should not be seen when they are in the fill_between location. But I still see them.
iptyhon --pylab
plot([0,1],[1,1],'r')
plot([0,1],[2,2],'g')
plot([0,1],[0.5,0.5],'b')
plot([0,1],[3,3],'k')
fill_between([0,0.25],[0,3.5],facecolor='LightGreen')
fill_between([0.3,0.45],[0,3.5],facecolor='Salmon')
fill_between([0.5,0.7],[0,3.5],facecolor='LightBlue')
fill_between([0.75,0.95],[0,3.5],facecolor='LightYellow')
When I use alpha = 0.5 I still get something that is not correct, the correct behavior is that each line will change is color when it is in the same location as the fill_between, but you see the color of the lines does not change...
plot([0,1],[1,1],'r')
plot([0,1],[2,2],'g')
plot([0,1],[0.5,0.5],'b')
plot([0,1],[3,3],'k')
fill_between([0,0.25],[0,3.5],facecolor='LightGreen',alpha=0.5)
fill_between([0.3,0.45],[0,3.5],facecolor='Salmon',alpha=0.5)
fill_between([0.5,0.7],[0,3.5],facecolor='LightBlue',alpha=0.5)
fill_between([0.75,0.95],[0,3.5],facecolor='LightYellow',alpha=0.5)
You can fix this using the zorder
kwarg:
plot([0,1],[1,1],'r',zorder=1)
plot([0,1],[2,2],'g',zorder=1)
plot([0,1],[0.5,0.5],'b',zorder=1)
plot([0,1],[3,3],'k',zorder=1)
fill_between([0,0.25],[0,3.5],facecolor='LightGreen',zorder=2)
fill_between([0.3,0.45],[0,3.5],facecolor='Salmon',zorder=2)
fill_between([0.5,0.7],[0,3.5],facecolor='LightBlue',zorder=2)
fill_between([0.75,0.95],[0,3.5],facecolor='LightYellow',zorder=2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With