嗨,我在python中使用fill_between命令,但是看起来fill_between总是在线图下面。
看这个例子,alpha=1,所以它不是不可见的。当所有的线都在两个位置之间的填充区时,不应该看到它们。但我仍然看到他们。
伊普顿——派拉布

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

当我使用alpha=0.5时,我仍然得到一些不正确的结果,正确的行为是,当每一行与中间的fill_位于同一位置时,每一行都会改变颜色,但是你看到行的颜色不会改变……
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)

最佳答案

您可以使用zorderkwarg修复此问题:

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)

关于python - fill_between始终位于绘图线下方,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28542933/

10-11 18:05