From 2aa3ad11f3df355e1e5e5f4f3d46aeab4a2b3229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michaela=20Le=C5=A1t=C3=A1kov=C3=A1?= Date: Tue, 6 Feb 2024 14:21:28 +0100 Subject: [PATCH] Added parameter 'show_plot' to 'plot_network' and 'show_plot' condition to 'network_animation' --- wntr/graphics/network.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/wntr/graphics/network.py b/wntr/graphics/network.py index 20dcf43fb..f95a3335b 100644 --- a/wntr/graphics/network.py +++ b/wntr/graphics/network.py @@ -47,7 +47,7 @@ def plot_network(wn, node_attribute=None, link_attribute=None, title=None, node_size=20, node_range=[None,None], node_alpha=1, node_cmap=None, node_labels=False, link_width=1, link_range=[None,None], link_alpha=1, link_cmap=None, link_labels=False, add_colorbar=True, node_colorbar_label='Node', link_colorbar_label='Link', - directed=False, ax=None, filename=None): + directed=False, ax=None, show_plot=True, filename=None): """ Plot network graphic @@ -127,6 +127,9 @@ def plot_network(wn, node_attribute=None, link_attribute=None, title=None, Axes for plotting (None indicates that a new figure with a single axes will be used) + show_plot: bool, optional + If True, show plot with plt.show() + filename : str, optional Filename used to save the figure @@ -243,7 +246,8 @@ def plot_network(wn, node_attribute=None, link_attribute=None, title=None, if filename: plt.savefig(filename) - plt.show(block=False) + if show_plot is True: + plt.show(block=False) return ax @@ -769,7 +773,7 @@ def network_animation(wn, node_attribute=None, link_attribute=None, title=None, ax = plot_network(wn, node_attribute=initial_node_values, link_attribute=initial_link_values, title=title_name, node_size=node_size, node_range=node_range, node_alpha=node_alpha, node_cmap=node_cmap, node_labels=node_labels, link_width=link_width, link_range=link_range, link_alpha=link_alpha, link_cmap=link_cmap, link_labels=link_labels, - add_colorbar=add_colorbar, directed=directed, ax=ax) + add_colorbar=add_colorbar, directed=directed, ax=ax, show_plot=False) def update(n): if node_attribute is not None: @@ -793,7 +797,7 @@ def update(n): ax = plot_network(wn, node_attribute=node_values, link_attribute=link_values, title=title_name, node_size=node_size, node_range=node_range, node_alpha=node_alpha, node_cmap=node_cmap, node_labels=node_labels, link_width=link_width, link_range=link_range, link_alpha=link_alpha, link_cmap=link_cmap, link_labels=link_labels, - add_colorbar=add_colorbar, directed=directed, ax=ax) + add_colorbar=add_colorbar, directed=directed, ax=ax, show_plot=False) return ax