【问题标题】:Matplotlib zorder axe hide other axe's linesMatplotlib zorder ax 隐藏其他 axe 的线条
【发布时间】:2018-03-28 00:13:33
【问题描述】:

我有 3 个带有一条或多条线的轴。 由于获得了光标所在行的选择器,我尝试更改包含该行的斧头的 zorder。

精度:我在一个FigureCanvasQTAgg派生的对象中

def onmove(self, event):
    """Methode appelée à chaque mouvement de souris dans le canvas."""
    for curr_axe in self.fig.get_axes():
        curr_axe.set_zorder(0)
        if curr_axe.in_axes(event):
            axe_x, axe_y = self.axe_dict[curr_axe.name].get_grid_coord(
                event.x, event.y)

        for line in curr_axe.get_lines():
            contain, _ = line.contains(event)
            if contain and line.get_label()[0] != '_':
                curr_axe.set_zorder(0.1)
                self.draw()
                self.current_line = line.get_label()

第一个斧头是简单地使用 Matplotlib Axes() 类添加在图中用 add_axes() 添加的

axe = Axes(figure, rect)
figure.add_axes(axe)

其他轴是通过 twinx() 创建的,并通过 add_axes() 添加到图形中

axe_2 = axe.twinx()
figure.add_axes(axe_2)
axe_3 = axe.twinx()
figure.add_axes(axe_3)

onmove 方法有效(我可以选择我想要的每一行),但是当第一个绘图斧头的 zorder 切换时,它隐藏了轴的线之后是怎样的。

示例:如果我的鼠标位于名为 ax 的 ax 线上,它会隐藏 axe_2 和 axe_3 的线。

【问题讨论】:

    标签: python matplotlib line z-order multiple-axes


    【解决方案1】:

    我猜问题是你的顶斧的背景颜色,它掩盖了下面的轴线。

    尝试从所有轴上移除背景,看看是否能解决问题。

    axe.patch.set_visible(False)
    axe_2.patch.set_visible(False)
    axe_3.patch.set_visible(False)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-19
      • 2018-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多