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

Look in to a Textual wrapper for Plottext #3029

Closed
willmcgugan opened this issue Jul 30, 2023 · 7 comments
Closed

Look in to a Textual wrapper for Plottext #3029

willmcgugan opened this issue Jul 30, 2023 · 7 comments
Assignees
Labels
enhancement New feature or request Task

Comments

@willmcgugan
Copy link
Collaborator

https://github.com/piccolomo/plotext/blob/master/readme/environments.md#rich

It already works with Rich. Perhaps we can add a Widget wrapper.

@davep davep self-assigned this Sep 7, 2023
@davep davep added enhancement New feature or request Task labels Sep 7, 2023
@rodrigogiraoserrao
Copy link
Contributor

@davep
Copy link
Contributor

davep commented Sep 14, 2023

The first thing that leaps out at me with this, and I'm sure there's a way around this, is that it follows the approach of some other plotting libraries I've seen and worked with where they're built for easy use in the REPL, but aren't so obvious for use in actual applications where you may have multiple separate plots happening at once (back in the day I remember matplotlib being quite difficult to use in this sense).

So a lot of the example code I'm seeing is stuff like:

import plotext as plt

plt.do_this()
plt.do_that()
plt.do_the_other()
plt.show()

with no examples of how you create two or more plots that have nothing to do with each other, in parallel; it all seems to be working on one single plot that's a singleton within the library.

Like I say: I would think (hope) there's a way of handling this, but I'm noting the issue here as something I need to dive into the docs further for.

@davep
Copy link
Contributor

davep commented Sep 14, 2023

After consuming the docs, and working through the code for the the library, it looks like the whole thing is very much built around the idea that any code using the library is only working on one plot at once (possibly with sub-plots; but they're part of the same parent plot); there's no (public) method of saying "give me a plot, let me work on that, oh and give me another plot and let me work on that too in parallel".

This sort of approach is fine for a simple procedural body of code that's only working on a single plot, but possibly not so great for trying to make a Textual widget from it; at least not without some compromises.

I was hoping we could make a widget that would be a thin wrapper around some plotting object within the library, and that building and updating multiple copies of such a widget would be easy and straightforward. Either I'm missing the obvious here, or this isn't going to be that simple.

None of this is to say it can't be done; it's more a case of the library doesn't seem to be designed to be "do stuff in parallel" friendly. (FWIW, I saw this exact same problem with matplotlib, which seems to be the inspiration for this library, back in the day -- eventually I seem to remember them adding a "class-based" system that allowed it)

@willmcgugan
Copy link
Collaborator Author

I think we have to wrap plottext in such a way that we can store the plot information, then in a render method build and extract that plot. That way we can supply methods to modify attributes, and lazily rebuild the plot as required.

@davep
Copy link
Contributor

davep commented Sep 14, 2023

Annoyingly, it's looking like something like that will have to be the approach, likely some sort of interface that captures the attempted function calls and arguments, and then plays them back in a single blocked call; that sort of thing.

@willmcgugan
Copy link
Collaborator Author

Pretty much.

An alternative might be to use processes to render the plots. That could be a huge win, in that multiple plots can be rendered in parallel. And you wouldn't have to deal with the issue of the singleton approach.

@davep davep closed this as completed Oct 4, 2023
@github-actions
Copy link

github-actions bot commented Oct 4, 2023

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Task
Projects
None yet
Development

No branches or pull requests

3 participants