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

[JOSS REVIEW] sp.visualize closes the plot for more than one sample? #21

Closed
j-faria opened this issue Mar 12, 2021 · 8 comments
Closed

Comments

@j-faria
Copy link

j-faria commented Mar 12, 2021

When running

y = sp.sample_ylm(nsamples=2).eval()
y.shape # (2, 256)

sp.visualize(y)

the plot shows up but closes right after.
There are a few plt.close() in starry_process.visualize.visualize which are likely the cause.

(This is part of joss-reviews/issues/3071)

@rodluger
Copy link
Owner

Thanks for raising this. It works for me when I do

python -c "from starry_process import StarryProcess; sp = StarryProcess(); y = sp.sample_ylm(nsamples=2).eval(); sp.visualize(y)"

I see a flickering animation switching between the two samples, and the plot remains open until I close it.

Are you in a Jupyter notebook?

@j-faria
Copy link
Author

j-faria commented Mar 12, 2021

Are you in a Jupyter notebook?

No, in the IPython console. It's fine if you don't want to support that, I was just surprised with the behaviour.

@rodluger
Copy link
Owner

Oh I definitely want to support that! But I still can't reproduce the issue, even inside an IPython session.

What do you get when you run

get_ipython()

in your session?

@j-faria
Copy link
Author

j-faria commented Mar 12, 2021

Ok, I tracked it down to the --pylab option to ipython (I know, considered evil!).
Without it, the plot shows and stays flickering.

Regardless of that option, I get this

get_ipython()
<IPython.terminal.interactiveshell.TerminalInteractiveShell at 0x7f9a8f0d2ed0>

@j-faria
Copy link
Author

j-faria commented Mar 12, 2021

Just to add that with ipython --matplotlib it also doesn't work.

@rodluger
Copy link
Owner

rodluger commented Mar 12, 2021

Interesting. Seems to be an issue with FuncAnimation. I'll keep digging -- thanks for pointing this out.

This is related:
https://stackoverflow.com/questions/19466825/ipython-pylab-matplotlib-animations-hang

@j-faria
Copy link
Author

j-faria commented Mar 12, 2021

It works if you return the animation from inside visualize and then from sp.visualize

@rodluger
Copy link
Owner

Ah, I think I got it. The --matplotlib and --pylab settings enable interactive mode, in which plt.show() is not blocking, so plt.close() immediately closes the animation. (I still want to call plt.close() in non-interactive mode, otherwise the plot stays open and calling visualize multiple times gobbles up RAM).

The fix is to simply check if plt.isinteractive() when calling plt.close(). Let me know if the latest commit fixed the issue fore you.

@rodluger rodluger changed the title sp.visualize closes the plot for more than one sample? [JOSS REVIEW] sp.visualize closes the plot for more than one sample? Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants