2017-06-05 62 views
3

我想绘制一系列的矩形和圆形,在前景中的圆圈。matplotlib补丁集合中的Zorder规范?

按照下面的帖子,我必须设置ZORDER说法: Patches I add to my graph are not opaque with alpha=1. Why?

这时候我单独绘制各界工作正常,但不是当我尝试把一系列圆的成收集和添加收藏,即

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) 

正常工作: enter image description here

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 是否有一个原因,或与补丁集合确实ZORDER工作在不同的,我不明白的方法呢?

回答

1

在第二种情况下,您希望PatchCollection具有定义的zorder,而不是PatchCollection的成员。因此,您需要为集合指定zorder。

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

谢谢!这很好。 – mzzx