我正在尝试绘制一系列矩形和圆形,圆形位于前景中。
根据下面的帖子,我必须设置 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)
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)
没有:
最佳答案
在第二种情况下,您希望 PatchCollection
具有定义的 zorder,而不是 PatchCollection
的成员。因此,您需要为集合指定 zorder。
circ=[]
circ.append(Circle ((1,1), 0.2))
coll=PatchCollection(circ, zorder=10)
ax.add_collection(coll)
关于python - matplotlib 补丁集合中的 Zorder 规范?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44361658/