有没有办法为matplotlib的饼图设置zorder?

3
我正在使用 matplotlib 饼图:https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.pie.html
我正在生成一个网络图,使用这些饼图。我在饼图中间画了一条线来区分两个不同的过程。我的问题是,当我把这条线画在中间时,它会覆盖所有的饼图,所以如果它们重叠,线就不能正确地分层:

我知道 matplotlib 的饼图没有 zorder 属性,但是否有办法模拟 zorder?这样我就可以为线条使用 zorder,并将一个饼图放在该线条上方进行重叠。
1个回答

4

pie() 返回一个补丁列表。这些单独的补丁有一个 zorder 属性,因此您可以循环遍历它们并调整它们的 zorder

fig,ax = plt.subplots()
ax.set_aspect('equal')
p1,t1 = plt.pie([50,50], center=(0,0))
p2,t2 = plt.pie([1,1,1,1], center=(1.2,0)) # this pie-chart is over the first one

[p.set_zorder(-1) for p in p2] # change the z-order of the patches so that the
                               # 2nd pie-chart ends up below the first one

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接