schollz
schollz

Reputation: 178

Is there any way to give matplotlib pie chart a zorder?

I am using the matplotlib pie chart: https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.pie.html.

I am generating a network diagram that uses these piecharts. I am drawing a line down the middle of the pie chart to delineate two different processes. My problem is that when I draw this line down the middle it will overlay ontop of all piecharts, so if they overlap, the lines will not be layered correctly:

I realize that there is no zorder for the matplotlib pie chart, but is there a way to get it to emulate a zorder? That way I can use the zorder for the line, and then layer a pie chart on top of that line to overlap it.

Upvotes: 3

Views: 817

Answers (1)

Diziet Asahi
Diziet Asahi

Reputation: 40667

pie() returns a list of patches. These individual patches have a zorder property, so you could loop over them and adjust their 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

Upvotes: 4

Related Questions