fill_between总是低于绘图线

时间:2015-02-16 13:49:39

标签: python matplotlib

您好我在python中使用fill_between命令,但看起来fill_between总是低于线图。

参见这个例子,alpha = 1,所以它不是不可见的。当它们位于fill_between位置时,不应该看到所有行。但我仍然看到他们。

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')

enter image description here

当我使用alpha = 0.5时,我仍然得到一些不正确的东西,正确的行为是每条线在与fill_between位于同一位置时会改变颜色,但是你看到线条的颜色没有改变...

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)

enter image description here

1 个答案:

答案 0 :(得分:6)

您可以使用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)

enter image description here