python - matplotlib 补丁集合中的 Zorder 规范?

标签 python matplotlib

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

根据下面的帖子,我必须设置 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 是否以我不理解的方式与补丁集合不同?

最佳答案

在第二种情况下,您希望 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/

相关文章:

使用命名空间的 Python ElementTree find()

python - 构建一个对 ReferenceProperty 有条件的 GQL 查询(针对 Google App Engine)

python - 从笔记本启动 IPython 集群有延迟

python - UserWarning : Matplotlib is currently using agg, 所以无法显示数字

python - 如何在pyqt中设置QThread的名称?

python - Elasticsearch:字段相对于其他字段的分布

python - 如何使用matplotlib绘制非线性函数?

python - 如何在 python 中将点更改为轴上的逗号

python - 我如何使用 numpy 和 matplotlib 绘制这个多项式分数?

python - Matplotlib 艺术家在放大时保持相同大小?