2

I have 3 axes with one or more lines. Due to get the picker of the line where my cursor is I tried to change the zorder of the axe which contain the line.

Precision : I am in a FigureCanvasQTAgg derived objet

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()

The first axe is simply created using the Matplotlib Axes() class add added in the figure with add_axes()

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

The others axes are created via twinx() and added to the figure with add_axes() too

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

The method onmove works (I can pick each line I want) but when the zorder of the first drawing axe switch it hide the lines of the axes how are after.

example : if my mouse is over a line of the axe named axe it hide the lines of axe_2 and axe_3.

enter image description here

Diziet Asahi
  • 38,379
  • 7
  • 60
  • 75
reynum
  • 125
  • 1
  • 1
  • 7

1 Answers1

2

I'm guessing the problem is the background color of your top axe, which masks the underlying axes lines.

try removing the backgrounds from all your axes and see if it solves the problem.

axe.patch.set_visible(False)
axe_2.patch.set_visible(False)
axe_3.patch.set_visible(False)
Diziet Asahi
  • 38,379
  • 7
  • 60
  • 75