gpt4 book ai didi

python - fill_between 总是低于绘图线

转载 作者:太空狗 更新时间:2023-10-30 01:01:12 26 4
gpt4 key购买 nike

您好,我在 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

最佳答案

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

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com