Zorder spec in matplotlib patch collections?

I am trying to plot a series of rectangles and circles with circles in the foreground.

As per the following post, I have to set the zorder argument: The patches I add to my graphics are not opaque with alpha = 1. Why?

This works great when I draw all the circles individually, but not when I try to put a series of circles in a collection and add a collection i.e.

fig,ax=plt.subplots(1)
p_fancy = FancyBboxPatch((1,1),
                         0.5, 0.5,
                         boxstyle="round,pad=0.1",
                         fc='beige',
                         ec='None', zorder=1)
ax.add_patch(p_fancy)
ax.set_xlim([0,2])
ax.set_ylim([0,2])
circ=patches.Circle ((1,1), 0.2, zorder=10)
ax.add_patch(circ)

      

works great: enter image description here while

fig,ax=plt.subplots(1)
p_fancy = FancyBboxPatch((1,1),
                         0.5, 0.5,
                         boxstyle="round,pad=0.1",
                         fc='beige',
                         ec='None', zorder=1)
ax.add_patch(p_fancy)
ax.set_xlim([0.,2])
ax.set_ylim([0.,2])
circ=[]
circ.append(patches.Circle ((1,1), 0.2, zorder=10))
coll=PatchCollection(circ)
ax.add_collection(coll)

      

:

enter image description here Is there a reason or zorder works differently with patch collections in ways that I don't understand?

+3


source to share


1 answer


In the second case, you want to PatchCollection

have a specific zorder, not members PatchCollection

. Thus, you need to specify the zorder for the collection.



circ=[]
circ.append(Circle ((1,1), 0.2))
coll=PatchCollection(circ, zorder=10)
ax.add_collection(coll)

      

+1


source







All Articles