I am trying to solve the same problem as this question, however my gui involves multiple axes and canvases.
Which is why I am trying to first perform this task on the first axis and the first canvas. The callback for mouse hover is working properly (I am yet to filter out unimportant events). The line.contains functions is working properly as well. I know this because I am printing the annotation data into my console and it is turning out to be as expected.
However the main problem is that I am unable to show the annotations on the canvas itself. Please find a snippet of the callback function for the "motion_notify_event" Can someone please help me debug this issue.
def hoverOnPlot(self,event):
print("Mouse hovering on plot ")
print(event)
line = self.plot_lines_list[0].lines[0]
point_on_line, ind = line.contains(event)
if point_on_line:
annotation_text = self.plot_lines_list[0].result_name + "(T: " + str(event.xdata) + ")"
print("Annotation Text Updated: ", annotation_text)
self.annotations = self._axes.annotate(annotation_text, xy=(event.xdata,event.ydata), xytext=(5,5),textcoords="offset points")
x = event.x
y = event.y
self.annotations.xy = (x,y)
self.annotations.set_text(annotation_text)
self.annotations.set_visible(True)
for canvas in self.canvas_list:
canvas.draw_idle()
else:
self.annotations.set_visible(False)
for canvas in self.canvas_list:
canvas.draw_idle()