Skip to content

Commit 0b1aeaf

Browse files
authored
Merge pull request #405 from mi-les/389-show-plot
Fixing `plt.show()` in `plot_network` for `network_animation`
2 parents 9173b56 + 2aa3ad1 commit 0b1aeaf

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

wntr/graphics/network.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def plot_network(wn, node_attribute=None, link_attribute=None, title=None,
4747
node_size=20, node_range=[None,None], node_alpha=1, node_cmap=None, node_labels=False,
4848
link_width=1, link_range=[None,None], link_alpha=1, link_cmap=None, link_labels=False,
4949
add_colorbar=True, node_colorbar_label='Node', link_colorbar_label='Link',
50-
directed=False, ax=None, filename=None):
50+
directed=False, ax=None, show_plot=True, filename=None):
5151
"""
5252
Plot network graphic
5353
@@ -127,6 +127,9 @@ def plot_network(wn, node_attribute=None, link_attribute=None, title=None,
127127
Axes for plotting (None indicates that a new figure with a single
128128
axes will be used)
129129
130+
show_plot: bool, optional
131+
If True, show plot with plt.show()
132+
130133
filename : str, optional
131134
Filename used to save the figure
132135
@@ -246,7 +249,8 @@ def plot_network(wn, node_attribute=None, link_attribute=None, title=None,
246249
if filename:
247250
plt.savefig(filename)
248251

249-
plt.show(block=False)
252+
if show_plot is True:
253+
plt.show(block=False)
250254

251255
return ax
252256

@@ -772,7 +776,7 @@ def network_animation(wn, node_attribute=None, link_attribute=None, title=None,
772776
ax = plot_network(wn, node_attribute=initial_node_values, link_attribute=initial_link_values, title=title_name,
773777
node_size=node_size, node_range=node_range, node_alpha=node_alpha, node_cmap=node_cmap, node_labels=node_labels,
774778
link_width=link_width, link_range=link_range, link_alpha=link_alpha, link_cmap=link_cmap, link_labels=link_labels,
775-
add_colorbar=add_colorbar, directed=directed, ax=ax)
779+
add_colorbar=add_colorbar, directed=directed, ax=ax, show_plot=False)
776780

777781
def update(n):
778782
if node_attribute is not None:
@@ -796,7 +800,7 @@ def update(n):
796800
ax = plot_network(wn, node_attribute=node_values, link_attribute=link_values, title=title_name,
797801
node_size=node_size, node_range=node_range, node_alpha=node_alpha, node_cmap=node_cmap, node_labels=node_labels,
798802
link_width=link_width, link_range=link_range, link_alpha=link_alpha, link_cmap=link_cmap, link_labels=link_labels,
799-
add_colorbar=add_colorbar, directed=directed, ax=ax)
803+
add_colorbar=add_colorbar, directed=directed, ax=ax, show_plot=False)
800804

801805
return ax
802806

0 commit comments

Comments
 (0)