How to get mousedown position in ui.matplotlib #3063
-
QuestionI would like to get the mouse position when clicking on an image displayed by ui.matplotlib. How can I achieve that? import numpy as np
from nicegui import ui, events
def mouse_handler(e: events.MouseEventArguments):
# How to get mouse position here
ui.notify("Mouse position is")
main_plot = ui.matplotlib(figsize=(8, 6))
main_plot.on("click", mouse_handler)
mat = np.random.rand(100, 100)
ax = main_plot.figure.gca()
ax.imshow(mat)
main_plot.update()
ui.run() |
Beta Was this translation helpful? Give feedback.
Answered by
falkoschindler
May 13, 2024
Replies: 1 comment 1 reply
-
Hi @nghia-vo, The event arguments with ui.matplotlib(figsize=(8, 6)).on('click', lambda e: print(e.args)).figure as fig:
fig.gca().imshow(np.random.rand(100, 100)) Output:
Unfortunately the mouse coordinates are in screen pixels and not in the data coordinate system 0..100. I'm not sure if there's a way to convert them reliably though. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
nghia-vo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @nghia-vo,
The event arguments
e
contain various attributes:Output: