代码之家  ›  专栏  ›  技术社区  ›  schollz

有没有办法给matplotlib饼图一个zorder?

  •  3
  • schollz  · 技术社区  · 7 年前

    我使用的是matplotlib饼图: https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.pie.html .

    我正在生成一个使用这些图表的网络图。我在饼图中间画了一条线来描绘两个不同的过程。我的问题是,当我从中间画这条线时,它将覆盖在所有图表的顶部,因此如果它们重叠,这些线将无法正确分层:

    我意识到没有 zorder 对于matplotlib饼图,有没有办法让它模拟zorder?这样我就可以使用 佐尔德 然后在该行的顶部放置一个饼图,使其重叠。

    1 回复  |  直到 7 年前
        1
  •  4
  •   Diziet Asahi    7 年前

    pie() 返回修补程序列表。这些单独的补丁具有 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

    推荐文章