有没有办法将数据放在标签前面?
Matplotlib 中的标签似乎总是显示在最顶部的覆盖层上,覆盖其后面的数据。
示例:
该图有 2 个红色文本注释。 底部覆盖着灰色的“Meteo”文本。
有没有办法将红色注释移到灰色文本标签上方?
我正在玩 zorder
但没有成功。
It seems that the labels in Matplotlib always are shown on the most top overlay, covering the data behind it.
Example:
The plot has 2 text annotations in red.
The bottom one is overlayed by a gray "Meteo" text.
Is there a way to move the red annotation above the gray text label?
I was playing with the zorder
but with no success.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它工作正常,但不是以您期望的方式工作。
每个元素都有它的
zorder
。甚至ax
也有默认的zorder=0
。这意味着,其中的所有元素(我们称之为层)都将具有最终的zorder=0
。但是当绘制zorder=0 渲染了
ax
layer时,zorder
分别应用于每个元素,并从下到上正确地放置在视图中。现在,您已经使用最终的
ax
layer。然后您将使用
fig.text
添加文本。它将文本添加到图形图层。现在你有两个对象要渲染;ax
layer 带有zorder = 0
和text
带有zorder=0
。您可以设置文本zorder=-1
,它将把文本放在ax
layer 下面,但如果ax
则它将不可见> 有扎实的背景。尝试在fig
layer 中添加具有更高或更低zorder
的另一个text
,它将正确绘制在顶部或位于另一个text
元素下方。It works properly, but not in a way You might expect.
Every element has it's
zorder
. Evenax
has defaultzorder=0
. It means, that all elements within that, let's call it a layer, will have finalzorder=0
.But when
ax
layer is drawn,zorder
is applied to every element respectively and are placed correctly in the view from bottom to the top.So now You have
ax
layer rendered with finalzorder=0
.Then You are adding text with
fig.text
. Which adds text to the figure layer. So now You have two objects to render;ax
layer withzorder = 0
andtext
withzorder=0
as well. You can set textzorder=-1
which will put text belowax
layer, but it will be invisible ifax
has solid background. Try to add anothertext
in thefig
layer with higher or lowerzorder
and it will be properly drawn on top or below anothertext
element.看来这只适用于 注释 但不适用于 text
下面是一个示例:
It seems this only works with annotations but not with text
Below an example: