netflow.probe.jupyter_app#

Functions

create_colorbar(values, title[, color_scale])

Create Plotly colorbar figure

create_legend(values, title[, color_scale])

Create Plotly legend figure

get_edge_colors(G, edge_color_attr[, edge_cmap])

get dict with color for each edge from edge attribute in the graph

get_node_colors(G, node_color_attr[, D, ...])

get dict with color for each node

matplotlib_to_plotly_cmap(cmap[, n, precision])

Convert matplotlib colormap to a plotly colorscale

nx_to_cytoscape(G[, pos, node_color_attr, ...])

Convert networkx graph to cytoscape syntax

render_pose(keeper, G, distance_key[, port])

Render the interactive POSE visualization in a JupyterLab notebook

renderer(keeper, pose_key, distance_key)

Construct the interactive POSE visualization for rendering in a JupyterLab notebook

netflow.probe.jupyter_app.create_colorbar(values, title, color_scale='viridis')[source]#

Create Plotly colorbar figure

Parameters:
  • values (list) – Values used to create the colorbar.

  • title (str) – Colorbar title.

  • color_scale (str) – The color scale to map values to the colorbar. Must be one of plotly supported color scales.

Returns:

fig – The Plotly colorbar figure.

Return type:

go.Figure

netflow.probe.jupyter_app.create_legend(values, title, color_scale=None)[source]#

Create Plotly legend figure

Parameters:
  • values ({list, ‘dict’}) –

    Values used to create the legend. May be provided as:

    • listValues that should be mapped to the color_scale.

      If values is a list, color_scale must be provided.

    • dictProvide the color for each value, keyed by the values.

      If values is a dict, color_scale is ignored.

  • title (str) – Legend title.

  • color_scale (str) – The color scale to map values to the legend. Must be one of plotly supported color scales. Ignored if values is a dict.

Returns:

fig – The Plotly legend figure.

Return type:

go.Figure

netflow.probe.jupyter_app.get_edge_colors(G, edge_color_attr, edge_cmap='jet')[source]#

get dict with color for each edge from edge attribute in the graph

Parameters:
  • G (networkx.Graph) – The network.

  • edge_color_attr (str) – Attribute to prescribe node colors.

  • edge_cmap (str) – Colormap applied to edges, must be found in matplotlib.colormaps.

Returns:

  • edge_color_map (dict) – The color for each edge, keyed by the edge.

  • cmap (go.Figure) – The Plotly colorbar figure.

netflow.probe.jupyter_app.get_node_colors(G, node_color_attr, D=None, node_cmap='jet')[source]#

get dict with color for each node

Parameters:
  • G (networkx.Graph) – The network.

  • node_color_attr ({str, int, numpy.array}) –

    Attribute to prescribe node colors.

    • str : color nodes by node attribute in G

    • inttreated as the id of an observation and the distance to that

      observation is used as the node colors, extracted from the corresponding row in D.

    • numpy.arrayexpected to be the same length as the number of nodes in G

      with the values to be mapped to colors for each node, ordered consecutively by node index.

  • D (numpy.ndarray (n, n)) – Must be provided if node_color_attr is int, otherwise it is ignored. Expected to be a symmetric matrix with values to be used as node colors. When node_color_attr is an int, each node i is colored according to D[node_color_attr, i].

  • node_cmap (str) – Colormap applied to nodes, must be found in matplotlib.colormaps.

Returns:

  • node_color_map (dict) – The color for each node, keyed by the node index.

  • cbar (go.Figure) – The Plotly colorbar figure.

netflow.probe.jupyter_app.matplotlib_to_plotly_cmap(cmap, n=11, precision=2)[source]#

Convert matplotlib colormap to a plotly colorscale

Parameters:
  • cmap – The matplotlib colormap.

  • n (int) – The number of entries considered for the Plotly colorscale.

  • precision (int) – The number of digits considered for rounding the scale values.

Returns:

The plotly colorscale.

Return type:

plotly_colorscale

netflow.probe.jupyter_app.nx_to_cytoscape(G, pos=None, node_color_attr=None, D=None, node_cmap='hsv', default_node_color='#888', edge_color_attr=None, edge_cmap='hsv', positions_records=None, return_cbar=False)[source]#

Convert networkx graph to cytoscape syntax

Parameters:
  • G (networkx.Graph) – The network.

  • pos ({None, dict}) – Node positions as returned from networkx.layout in the form {node: np.array([x, y])}. If None, default computes layout from network.layout.kamada_kawai.

  • node_color_attr ({str, int, numpy.array}) –

    Attribute to prescribe node colors.

    • str : color nodes by node attribute in G

    • inttreated as the id of an observation and the distance to that

      observation is used as the node colors, extracted from the corresponding row in D.

    • numpy.arrayexpected to be the same length as the number of nodes in G

      with the values to be mapped to colors for each node, ordered consecutively by node index.

  • D (numpy.ndarray (n, n)) – Must be provided if node_color_attr is int, otherwise it is ignored. Expected to be a symmetric matrix with values to be used as node colors. When node_color_attr is an int, each node i is colored according to D[node_color_attr, i].

  • node_cmap (str) – Colormap applied to nodes, must be found in matplotlib.colormaps.

  • default_node_color (str) – The default node color.

  • edge_color_attr (str) – Attribute to prescribe node colors.

  • edge_cmap (str) – Colormap applied to edges, must be found in matplotlib.colormaps.

  • positions_records ({None, dict}) – Optional. Provide dictionary of pre-computed node positions keyed by the name of the layout. If provided, it will be updated if a new layout position is computed.

  • return_cbar (bool) – If True, also return edge and node colorbars.

Returns:

  • elements (dict) – The cytoscape network elements.

  • node_cbar_vis ({go.Figure, None}) – Only returned if return_cbar=True. If the node colors are mapped to a feature value, the corresponding colorbar figure is returned as a go.Figure. Otherwise, None is returned.

  • edge_cbar_vis ({go.Figure, None}) – Only returned if return_cbar=True. If the edge colors are mapped to a feature value, the corresponding colorbar figure is returned as a go.Figure. Otherwise, None is returned.

netflow.probe.jupyter_app.render_pose(keeper, G, distance_key, port=8090)[source]#

Render the interactive POSE visualization in a JupyterLab notebook

Parameters:
  • keeper (netflow.Keeper) – The keeper.

  • G (networkx.Graph) – The network (intended to be the POSE network).

  • distance_key (str) – The key to reference the distance stored in keeper used to identify node colors relative to a particular observation (intended to be the distance used to construct the POSE).

netflow.probe.jupyter_app.renderer(keeper, pose_key, distance_key)[source]#

Construct the interactive POSE visualization for rendering in a JupyterLab notebook

Parameters:
  • keeper (netflow.Keeper) – The keeper.

  • G (networkx.Graph # here) – The network (intended to be the POSE network). # here

  • pose_key (str) – The key to reference the POSE stored in keeper.graphs.

  • distance_key (str) – The key to reference the distance stored in keeper used to identify node colors relative to a particular observation (intended to be the distance used to construct the POSE).

Returns:

app – The app object.

Return type:

JupyterDash