matplotlib 补丁集合中的 Zorder 规范? [英] Zorder specification in matplotlib patch collections?

查看:44
本文介绍了matplotlib 补丁集合中的 Zorder 规范?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绘制一系列矩形和圆形,而圆形位于前景中.

根据以下文章,我必须设置zorder参数:而

fig,ax=plt.subplots(1)p_fancy = FancyBboxPatch((1,1),0.5, 0.5,boxstyle ="round,pad = 0.1",fc ='米色',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)

不是:

是否有原因,或者 zorder 是否以我不理解的方式与补丁集合的工作方式不同?

解决方案

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

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

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

According to the following post, I have to set the zorder argument: Patches I add to my graph are not opaque with alpha=1. Why?

This works fine when I plot all the circles individually, but not when I try to place a series of circles into a collection and add the 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 fine: 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)

does not:

Is there a reason, or does zorder work differently with patch collections in ways that I don't understand?

解决方案

In the second case you want the PatchCollection to have a defined zorder, not the members of the PatchCollection. Thus, you need to specify zorder for the collection.

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

这篇关于matplotlib 补丁集合中的 Zorder 规范?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆