-
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
Fixing plt.show()
in plot_network
for network_animation
#405
base: main
Are you sure you want to change the base?
Conversation
…on to 'network_animation'
Thanks for submitting this PR! We'll test this out in Jupyter notebooks and other IDEs and get back to you. |
@mi-les, what platform are you using for running notebooks? I use VSCode, which is notoriously bad at showing plots in notebooks, and I still only see the first frame when I try to run an example using your code. I think this is an issue with VSCode rather than your code, so I would like to check it on a whatever platform you used. |
@kbonney I am using VS Code as well, together with the import wntr
import matplotlib.pyplot as plt
# from wntr.graphics.network import network_animation
from IPython.display import HTML
wn = wntr.network.WaterNetworkModel("examples/networks/Net1.inp")
sim = wntr.sim.EpanetSimulator(wn)
results = sim.run_sim()
demand = results.node["demand"]
anim = wntr.graphics.network_animation(wn, node_attribute=demand.iloc[0:4])
# plt.show()
HTML(anim.to_jshtml()) With the original code, this did not work. Using |
This works for me, but as stated above, the first frame is displayed in addition to the network animation and the user would need to add |
Showing the last slide can be suppressed by: html = HTML(anim.to_jshtml())
display(html)
plt.close() I agree that this is a bit inelegant, but I see the problem on the matplotlib/Jupyter side. The |
The lingering first frame is more of an issue with how Jupyter works by default than how the code is set up. By default, jupyter will always capture the initial plotted figure and display it, in addition to the display of the animation. There are a lot of ideas in this SEO thread, but none of them solve the problem without additional work on the user's end. Even if we directly return the HTML object, jupyter still finds that initial frame and will attempt to plot it in the output. The cleanest solution I have found is to use the jupyter magic command
|
Here's a draft of something we could paste into the docstring and/or the network animation section of the graphics page in the documentation:
|
Summary
Solves issue #389 which describes problems using
wntr.graphics.network.network_animation
in Jupyter Notebooks by adding ashow_plot
parameter to thewntr.graphics.network.plot_network
function.show_plot
is set to 'True' by default onwntr.graphics.network.plot_network
, but changed toFalse
withinwntr.graphics.network.network_animation
. This makesnetwork_animation
work as intended.Tests and documentation
None; docstring for the
show_plot
parameter of thewntr.graphics.network.plot_network
function addedAcknowledgement
By contributing to this software project, I acknowledge that I have reviewed the software quality assurance guidelines and that my contributions are submitted under the Revised BSD License.