Python matplotlib 孵化fill_between 没有边缘?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18386106/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
matplotlib hatched fill_between without edges?
提问by Jdog
I have a region I'd like to hatch which borders on an existing plot line (of the same colour) that is dashed.
我有一个区域,我想在虚线的现有绘图线(相同颜色)上填充哪些边界。
However, when I use fill_between
the region to be hatched has a border drawn around it also. This border seems share properties with the lines that create the hatching so I cannot set edgecolour to "none" or set linestyle as "--" as the hatching is similarly affected.
但是,当我使用fill_between
要阴影的区域时,它周围也会绘制一个边框。此边框似乎与创建影线的线条共享属性,因此我无法将 edgecolour 设置为“none”或将线型设置为“--”,因为影线也受到类似的影响。
import matplotlib.pyploy as plt
plt.plot([0,1],[0,1],ls="--",c="b")
plt.fill_between([0,1],[0,1],color="none",hatch="X",edgecolor="b")
plt.show()
In this example I'd want the diagonal line from 0,0 to 1,1 to be dashed.
在这个例子中,我希望从 0,0 到 1,1 的对角线是虚线。
Many thanks in advance.
提前谢谢了。
采纳答案by Greg
>2.0.1 UpdateAs commented by @CatherineHolloway you need to use facecolor
instead of color
now:
>2.0.1 更新正如@CatherineHolloway 所评论的,您需要使用facecolor
而不是color
现在:
import matplotlib.pyplot as plt
plt.plot([0,1],[0,1],ls="--",c="b")
plt.fill_between([0,1],[0,1], facecolor="none", hatch="X", edgecolor="b", linewidth=0.0)
plt.show()
Former answer
以前的回答
This seems to do the trick!
这似乎可以解决问题!
import matplotlib.pyplot as plt
plt.plot([0,1],[0,1],ls="--",c="b")
plt.fill_between([0,1],[0,1], color="none", hatch="X", edgecolor="b", linewidth=0.0)
plt.show()