python - Matplotlib zorder ax 隐藏其他轴的线

标签 python matplotlib line z-order multiple-axes

我有 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() 简单创建的,在图中添加了 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 的斧头线上,则会隐藏 axe_2 和 axe_3 的线。

enter image description here

最佳答案

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

尝试从所有轴上删除背景,看看是否可以解决问题。

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

关于python - Matplotlib zorder ax 隐藏其他轴的线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46770903/

相关文章:

python - scipy.integrate.ode.integrate() 可选的 `step` 和 `relax` 参数有什么作用?

python - 如何使用 Python 绘制其数据沿 x 轴分布不均匀的二维矩阵?

Java无法正确计算点到线的距离

command-line - Vim,转到特定行后执行操作

python - 线段和三角形之间的 3d 交集

python - 阻止由 selenium firefox 驱动程序产生的弹出窗口

python - 计算 python 脚本执行时间的最简单方法?

python - 为什么 from ... import ... 语句包含隐式导入?

python matplotlib : How can I place text in a given area?

python - matplotlib 中没有网格的极坐标图