0

I have a matplotlib.PatchCollection that I want to add to a plot. But I also have Text and other Patches I am adding straight onto the plot. So it looks like this:

node.shape = RegularPolygon((node.posX, node.posY),
                            6,
                radius = node.radius,
                                    edgecolor = 'none',
                                    facecolor = node.fillColor,
                                    zorder = node.zorder)


self.patches.append(node.shape)
self.p = PatchCollection(self.patches, edgecolor = 'none', match_original=True )       
self.plotAxes.add_collection(self.p) 

#Two previously instantiated patches (they are visible)
self.plotAxes.add_artist(selectionRect)
self.plotAxes.add_artist(brushShape)

self.plotCanvas.draw()

I want my Patches in the collection to be drawn first and then the selctionRect and brushShape to be drawn afterwards because they can overlap the Patches in the collection. If they do, they should be visible. However, my plot always shows the Patches in the collection as if they've been drawn last. How can I get around this? Any help is appreciated.

Edit: One thing that appears to work is to keep 2 PatchCollections. However, when I do this, it seems that I can never set the visibilities to false. Does the PatchCollection set the reset the values or something?

4

1 回答 1

0

正如亚当在你想要设置的评论中所说的那样,zorder当它们被绘制在彼此之上时,它设置了什么顺序的东西,高的zorder东西将与低的东西重叠zorder

一切都有一个 default zorder,但是您可以通过将zorderkwarg 添加到函数调用来覆盖该值。这是一个Artistkwarg,所以基本上任何绘图函数都应该尊重它(如果你发现一个没有向 github 站点提交错误报告的函数)

前任

plt.figure()
ax = plt.gca()
ax.plot(range(5), zorder=2, lw=10)
ax.plot(range(5)[::-1], zorder=1, lw=10)

对比

plt.figure()
ax = plt.gca()
ax.plot(range(5), zorder=1, lw=10)
ax.plot(range(5)[::-1], zorder=2, lw=10)

zorder 演示

于 2013-01-25T05:47:26.350 回答