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

Get a plot as a string #10

Closed
JoshKarpel opened this issue May 8, 2021 · 6 comments
Closed

Get a plot as a string #10

JoshKarpel opened this issue May 8, 2021 · 6 comments
Assignees
Labels
feature request New feature or request

Comments

@JoshKarpel
Copy link

JoshKarpel commented May 8, 2021

I'm working on a tool that I would love to be able to integrate uniplot into, but I'm running into a problem: I need to capture the output as a string so that I can display it elsewhere. Right now, uniplot.plot prints directly to stdout: https://github.com/olavolav/uniplot/blob/master/uniplot/uniplot.py#L74

I'm not sure how to square this with the interactive features implemented in that function. Perhaps a helper function could be extracted that returns the plot as a string? Then I could call that function from my tool to get the string that uniplot.plot would have displayed.

Happy to do the work on this if you can provide some guidance on how you'd like it implemented!

@olavolav
Copy link
Owner

Hi @JoshKarpel thanks for the request!

Should be possible fairly easily. So let's say you had a function plot_to_string that has the same signature as plot but without the interactive option, would that help already?

In particular right now uniplot does not guarantee a horizontal dimension, as width is the width option plus how much space the vertical axis labels take. Depending on how you want to integrate the output, would that be an issue for you?

@olavolav olavolav added feature request New feature or request question Further information is requested labels May 10, 2021
@JoshKarpel
Copy link
Author

JoshKarpel commented May 11, 2021

So let's say you had a function plot_to_string that has the same signature as plot but without the interactive option, would that help already?

Definitely!

In particular right now uniplot does not guarantee a horizontal dimension, as width is the width option plus how much space the vertical axis labels take. Depending on how you want to integrate the output, would that be an issue for you?

I don't think it's a deal breaker, but it might make things easier. I could certainly do without it for a first pass!

My current thinking is that I'll probably be sticking the plot output inside a https://rich.readthedocs.io/en/stable/reference/text.html#rich.text.Text , and I can disable wrapping - but that means the plot might get cut off if I don't guess the width right.

@olavolav
Copy link
Owner

Thanks @JoshKarpel!

I'll have a look over the weekend, but I think it shouldn't be too hard, might actually end up with more readable code when splitting the plot generation and text output.

I also thought about limiting the bounding box of the plot, this should also be possible by computing the vertical axis labels first, and then shrinking the plot window if needed. But I'll leave this for a later date.

@olavolav olavolav removed the question Further information is requested label May 12, 2021
@olavolav olavolav self-assigned this May 12, 2021
olavolav added a commit that referenced this issue May 15, 2021
This adds functionality for #10. Version bump to 0.4.4.
@olavolav
Copy link
Owner

Hi @JoshKarpel I just added such a function in version 0.4.4 🚢

Haven't gotten around to do the "hard cap on line length" part yet, but hope this helps already.

If you can share I'd be curious to see what you end up with on your side!

@JoshKarpel
Copy link
Author

JoshKarpel commented May 15, 2021

Hi @JoshKarpel I just added such a function in version 0.4.4 🚢

Haven't gotten around to do the "hard cap on line length" part yet, but hope this helps already.

If you can share I'd be curious to see what you end up with on your side!

It's working really well so far! JoshKarpel/spiel#33

image

@olavolav
Copy link
Owner

Very cool! 😄 Looking forward to see how Spiel progresses

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

No branches or pull requests

2 participants