-
Notifications
You must be signed in to change notification settings - Fork 176
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
network_animation
does not behave as intended in Jupyter Notebooks
#389
Comments
Thanks for posting this issue. I don't believe I've ever created a network animation in jupyter notebooks, so this is great to know. plt.show(block=False) should have been added to all our graphics functions, but it looks like this is not the case (block=False allows the tests to continue running without closing the plot), see #265. There are other ways we could handle this if needed. For animation, it sounds like we don't want to show the plots to avoid multiple plots in a jupyter notebook. Feel free to post a PR and we can test this out for the various run environments (command line and testing, jupyter notebooks, spyder, etc.). |
Summary
I had difficulty using
anim = wntr.graphics.network_animation(wn)
and getting the desired behavior in a Jupyter Notebook (+VS Code), i.e. something where I can replay the network results and click through the timesteps.The best way to do this would be to use
from IPython.display import HTML
and thenHTML(anim.to_jshtml())
. However, the example code below would lead to problems: instead of the desired behavior as demonstrated here, I ended up with a lot of single frames plotted below one another, and an empty interactive video frame.I figured that this is because the function
plot_network
, which is called bynetwork_animation
, plots each frame withplt.show(block=False)
.I'd suggest having an extra argument in
plot_network
, for exampleshow_plot
, set toTrue
by default, but changed toFalse
when called within thenetwork_animation
function. With this solution, also demonstrated below, everything works as expected.Example
Environment
Provide information on your computing environment.
Additional context
suggestion:
I'll be happy to create a PR for this if needed.
The text was updated successfully, but these errors were encountered: