[Question] How to get the coordinate of the position of clicking mouse on MatplotlibChart? #4067
-
QuestionIn the following example code, the onclick event cannot be triggered Code sampleimport matplotlib
import matplotlib.pyplot as plt
import flet as ft
from flet.matplotlib_chart import MatplotlibChart
# Use the WebAgg backend
matplotlib.use("WebAgg")
def main(page: ft.Page):
def onclick(event):
"""Mouse click event handler"""
if event.xdata is not None and event.ydata is not None:
print(f'Mouse click coordinates: x={event.xdata}, y={event.ydata}')
# Create a figure and axis
fig, ax = plt.subplots()
# Plot some data so we can see where the mouse clicks
ax.plot([1, 2, 3, 4], [10, 20, 25, 30], 'r-')
# Connect the mouse click event
cid = fig.canvas.mpl_connect('button_press_event', onclick)
# Add the Matplotlib chart to the page
chart = MatplotlibChart(fig, expand=True)
page.add(chart)
# Start the application
ft.app(target=main, view=ft.WEB_BROWSER) Error messageNo response ------------------------------------------------------
|
Beta Was this translation helpful? Give feedback.
Answered by
ndonkoHenri
Sep 29, 2024
Replies: 1 comment 1 reply
-
Matplotlib and Plotly charts available in Flet are non-interactive, because it's just an image of your figure. For interactivity, consider trying the others. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
HuaxiaGoodBoy
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Matplotlib and Plotly charts available in Flet are non-interactive, because it's just an image of your figure. For interactivity, consider trying the others.