【问题标题】:Zorder specification in matplotlib patch collections?matplotlib 补丁集合中的 Zorder 规范?
【发布时间】:2017-06-05 16:12:21
【问题描述】:

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

根据下面的帖子,我必须设置 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)

没有:

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

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-02
      • 1970-01-01
      • 2015-03-12
      • 1970-01-01
      • 1970-01-01
      • 2017-01-06
      • 2020-12-11
      • 2018-04-24
      相关资源
      最近更新 更多