wntr.graphics.network module¶
The wntr.graphics.network module includes methods plot the water network model.
- wntr.graphics.network.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)[source]¶
Plot network graphic
- Parameters
wn (wntr WaterNetworkModel) – A WaterNetworkModel object
node_attribute (None, str, list, pd.Series, or dict, optional) –
If node_attribute is a string, then a node attribute dictionary is created using node_attribute = wn.query_node_attribute(str)
If node_attribute is a list, then each node in the list is given a value of 1.
If node_attribute is a pd.Series, then it should be in the format {nodeid: x} where nodeid is a string and x is a float.
If node_attribute is a dict, then it should be in the format {nodeid: x} where nodeid is a string and x is a float
link_attribute : None, str, list, pd.Series, or dict, optional
If link_attribute is a string, then a link attribute dictionary is created using edge_attribute = wn.query_link_attribute(str)
If link_attribute is a list, then each link in the list is given a value of 1.
If link_attribute is a pd.Series, then it should be in the format {linkid: x} where linkid is a string and x is a float.
If link_attribute is a dict, then it should be in the format {linkid: x} where linkid is a string and x is a float.
title (str, optional) – Plot title
node_size (int, optional) – Node size
node_range (list, optional) – Node range ([None,None] indicates autoscale)
node_alpha (int, optional) – Node transparency
node_cmap (matplotlib.pyplot.cm colormap or list of named colors, optional) – Node colormap
node_labels (bool, optional) – If True, the graph will include each node labelled with its name.
link_width (int, optional) – Link width
link_range (list, optional) – Link range ([None,None] indicates autoscale)
link_alpha (int, optional) – Link transparency
link_cmap (matplotlib.pyplot.cm colormap or list of named colors, optional) – Link colormap
link_labels (bool, optional) – If True, the graph will include each link labelled with its name.
add_colorbar (bool, optional) – Add colorbar
node_colorbar_label (str, optional) – Node colorbar label
link_colorbar_label (str, optional) – Link colorbar label
directed (bool, optional) – If True, plot the directed graph
ax (matplotlib axes object, optional) – Axes for plotting (None indicates that a new figure with a single axes will be used)
filename (str, optional) – Filename used to save the figure
- Returns
ax (matplotlib axes object)
- wntr.graphics.network.plot_interactive_network(wn, node_attribute=None, node_attribute_name='Value', title=None, node_size=8, node_range=[None, None], node_cmap='Jet', node_labels=True, link_width=1, add_colorbar=True, reverse_colormap=False, figsize=[700, 450], round_ndigits=2, add_to_node_popup=None, filename='plotly_network.html', auto_open=True)[source]¶
Create an interactive scalable network graphic using plotly. :param wn: A WaterNetworkModel object :type wn: wntr WaterNetworkModel :param node_attribute:
If node_attribute is a string, then a node attribute dictionary is created using node_attribute = wn.query_node_attribute(str)
If node_attribute is a list, then each node in the list is given a value of 1.
If node_attribute is a pd.Series, then it should be in the format {nodeid: x} where nodeid is a string and x is a float. The time index is not used in the plot.
If node_attribute is a dict, then it should be in the format {nodeid: x} where nodeid is a string and x is a float
- Parameters
node_attribute_name (str, optional) – The node attribute name, which is used in the node popup and node legend
title (str, optional) – Plot title
node_size (int, optional) – Node size
node_range (list, optional) – Node range ([None,None] indicates autoscale)
node_cmap (palette name string, optional) – Node colormap, options include Greys, YlGnBu, Greens, YlOrRd, Bluered, RdBu, Reds, Blues, Picnic, Rainbow, Portland, Jet, Hot, Blackbody, Earth, Electric, Viridis
node_labels (bool, optional) – If True, the graph will include each node labelled with its name and attribute value.
link_width (int, optional) – Link width
add_colorbar (bool, optional) – Add colorbar
reverse_colormap (bool, optional) – Reverse colormap
figsize (list, optional) – Figure size in pixels
round_ndigits (int, optional) – Number of digits to round node values used in the label
add_to_node_popup (None or pd.DataFrame, optional) – To add additional information to the node popup, use a DataFrame with node name as index and attributes as values. Column names will be added to the popup along with each value for a given node.
filename (string, optional) – HTML file name
auto_open (bool, optional) – Open the HTML file after creation
- wntr.graphics.network.plot_leaflet_network(wn, node_attribute=None, link_attribute=None, node_attribute_name='Value', link_attribute_name='Value', node_size=2, node_range=[None, None], node_cmap=['cornflowerblue', 'forestgreen', 'gold', 'firebrick'], node_cmap_bins='cut', node_labels=True, link_width=2, link_range=[None, None], link_cmap=['cornflowerblue', 'forestgreen', 'gold', 'firebrick'], link_cmap_bins='cut', link_labels=True, add_legend=False, round_ndigits=2, zoom_start=13, add_to_node_popup=None, add_to_link_popup=None, filename='leaflet_network.html')[source]¶
Create an interactive scalable network graphic on a Leaflet map using folium. :param wn: A WaterNetworkModel object :type wn: wntr WaterNetworkModel :param node_attribute:
If node_attribute is a string, then a node attribute dictionary is created using node_attribute = wn.query_node_attribute(str)
If node_attribute is a list, then each node in the list is given a value of 1.
If node_attribute is a pd.Series, then it should be in the format {nodeid: x} where nodeid is a string and x is a float.
If node_attribute is a dict, then it should be in the format {nodeid: x} where nodeid is a string and x is a float
- Parameters
link_attribute (None, str, list, pd.Series, or dict, optional) –
If link_attribute is a string, then a link attribute dictionary is created using edge_attribute = wn.query_link_attribute(str)
If link_attribute is a list, then each link in the list is given a value of 1.
If link_attribute is a pd.Series, then it should be in the format {linkid: x} where linkid is a string and x is a float.
If link_attribute is a dict, then it should be in the format {linkid: x} where linkid is a string and x is a float.
node_attribute_name (str, optional) – The node attribute name, which is used in the node popup and node legend
link_attribute_name (str, optional) – The link attribute name, which is used in the link popup and link legend
node_size (int, optional) – Node size
node_range (list, optional) – Node range ([None,None] indicates autoscale)
node_cmap (list of color names, optional) – Node colors
node_cmap_bins (string, optional) – Node color bins, ‘cut’ or ‘qcut’
node_labels (bool, optional) – If True, the graph will include each node labelled with its name.
link_width (int, optional) – Link width
link_range (list, optional) – Link range ([None,None] indicates autoscale)
link_cmap (list of color names, optional) – Link colors
link_cmap_bins (string, optional) – Link color bins, ‘cut’ or ‘qcut’
link_labels (bool, optional) – If True, the graph will include each link labelled with its name.
add_legend (bool, optional) – Add a legend to the map
round_ndigits (int, optional) – Rounds digits in the popup
zoom_start (int, optional) – Zoom start used to set initial scale of the map
add_to_node_popup (None or pd.DataFrame, optional) – To add additional information to the node popup, use a DataFrame with node name as index and attributes as values. Column names will be added to the popup along with each value for a given node.
add_to_link_popup (None or pd.DataFrame, optional) – To add additional information to the link popup, use a DataFrame with link name as index and attributes as values. Column names will be added to the popup along with each value for a given link.
filename (str, optional) – Filename used to save the map
- wntr.graphics.network.network_animation(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, directed=False, ax=None, repeat=True)[source]¶
Create a network animation :param wn: A WaterNetworkModel object :type wn: wntr WaterNetworkModel :param node_attribute: Node attributes stored in a pandas DataFrames, where the index is
time and columns are the node name
- Parameters
link_attribute (pd.DataFrame, optional) – Link attributes stored in a pandas DataFrames, where the index is time and columns are the link name
title (str, optional) – Plot title
node_size (int, optional) – Node size
node_range (list, optional) – Node range ([None,None] indicates autoscale)
node_alpha (int, optional) – Node transparency
node_cmap (matplotlib.pyplot.cm colormap or list of named colors, optional) – Node colormap
node_labels (bool, optional) – If True, the graph will include each node labelled with its name.
link_width (int, optional) – Link width
link_range (list, optional) – Link range ([None,None] indicates autoscale)
link_alpha (int, optional) – Link transparency
link_cmap (matplotlib.pyplot.cm colormap or list of named colors, optional) – Link colormap
link_labels (bool, optional) – If True, the graph will include each link labelled with its name.
add_colorbar (bool, optional) – Add colorbar
directed (bool, optional) – If True, plot the directed graph
repeat (bool, optional) – If True, the animation will repeat
- Returns
matplotlib animation