Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interactive matplotlib charts #72

Open
kaylai opened this issue Dec 12, 2023 · 4 comments
Open

Interactive matplotlib charts #72

kaylai opened this issue Dec 12, 2023 · 4 comments
Labels
enhancement New features, or improvements to existing features.

Comments

@kaylai
Copy link

kaylai commented Dec 12, 2023

What is the problem or limitation you are having?

It would be great to have intractability within a toga_chart.Chart() object. I understand Chart() is calling matplotlib. Does that mean any matplotlib styling/functionality can be used within a Chart() object? Currently, a Chart() is plotted as a static thing. I'd like to enable the standard matplotlib controls (pan, zoom, save) and also add a DraggableLine element. Is intractability currently possible, or will this feature be added?

Describe the solution you'd like

If this is not already possible given Chart() is using matplotlib, I would love to see this added as a feature and/or have someway to call any matplotlib stuff (e.g., pyplot.ion).

Describe alternatives you've considered

I tried just calling pyplot.ion, but that does not enable intractability.

Additional context

No response

@kaylai kaylai added the enhancement New features, or improvements to existing features. label Dec 12, 2023
@freakboy3742
Copy link
Member

Thanks for the suggestion.

It's not currently possible, but it's certainly in the realm of the possible. Toga's Canvas element (which is what Chart is built on) has handlers to capture mouse clicks and movements; presumably there is some interface that can be be implemented in a matplotlib backend that will convert canvas-level mouse clicks into the relevant Matplotlib commands.

I don't have any immediate plans to work on this, but if you're interested, I'd encourage you to take a look yourself. Although it might seem daunting, the code for toga-chart is a relatively straightforward mapping from Matplotlib's backend API to Toga's Canvas API. It is implemented as a matplotlib backend, the core of which is a subclass of matplotlib.backend_bases.RendererBase. From a quick look at the docs, there is a button_press_handler that is likely at the core of how interactive charts work. You might be able to learn more by poking around the source code for one of the existing interactive backends (Tk, GTK or Qt).

@kaylai
Copy link
Author

kaylai commented Dec 13, 2023

Hi there, thanks for the information and resources! I think I will take a peak at the matplotlib backend and at how Tk handles that integration. I doubt I'll make much progress, but if I do, I'll get in touch about contributing via a PR.

@davetapley
Copy link

@kaylai did you get anywhere with this? 🙏🏻

@kaylai
Copy link
Author

kaylai commented Sep 26, 2024

@kaylai did you get anywhere with this? 🙏🏻

Unfortunately no 😔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New features, or improvements to existing features.
Projects
None yet
Development

No branches or pull requests

3 participants