gpt4 book ai didi

python - matplotlib.legend.set_zorder() 在 ipython 笔记本中不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 05:41:53 25 4
gpt4 key购买 nike

这是一件让我非常恼火的事情。我已按照 strange matplotlib zorder behavior with legend and errorbar 中的指示进行操作但它不起作用。这是一个非常简短的工作示例

x = np.linspace(0,10) 
y = (x-5)**2
plt.plot(x,y,label='test curve',zorder=100)
plt.legend(loc='center right').set_zorder(102)

如果您尝试这样做,您会发现图例仍在曲线下方,尽管使用了 zordering。有谁知道为什么吗?

http://i.stack.imgur.com/MOekP.png

我在 ipython 3.1.0 上使用 matplotlib 1.3.1

最佳答案

根据@cel 的评论,我同意您需要为图例添加不透明背景。尝试添加:

leg=plt.legend(loc='center right')
leg.set_zorder(102)
leg.get_frame().set_facecolor('w')

也可以在 matplotlibrc 或通过 plt.rcParams 设置 legend.facecolor


或者确保图例框架的 fill 设置为 True:

print leg.get_frame().get_fill()

如果打印出False,试试

leg.get_frame().set_fill(True)

关于python - matplotlib.legend.set_zorder() 在 ipython 笔记本中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33648920/

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