Visualization

Visualization tools.

Graphs

sknetwork.visualization.graphs.svg_graph(adjacency: Optional[scipy.sparse.csr.csr_matrix] = None, position: Optional[numpy.ndarray] = None, names: Optional[numpy.ndarray] = None, labels: Optional[Iterable] = None, scores: Optional[Iterable] = None, membership: Optional[scipy.sparse.csr.csr_matrix] = None, seeds: Union[list, dict] = None, width: Optional[float] = 400, height: Optional[float] = 300, margin: float = 20, margin_text: float = 3, scale: float = 1, node_order: Optional[numpy.ndarray] = None, node_size: float = 7, node_size_min: float = 1, node_size_max: float = 20, display_node_weight: bool = False, node_weights: Optional[numpy.ndarray] = None, node_width: float = 1, node_width_max: float = 3, node_color: str = 'gray', display_edges: bool = True, edge_labels: Optional[list] = None, edge_width: float = 1, edge_width_min: float = 0.5, edge_width_max: float = 20, display_edge_weight: bool = True, edge_color: Optional[str] = None, label_colors: Optional[Iterable] = None, font_size: int = 12, directed: bool = False, filename: Optional[str] = None) → str[source]

Return SVG image of a graph.

Parameters
  • adjacency – Adjacency matrix of the graph.

  • position – Positions of the nodes.

  • names – Names of the nodes.

  • labels – Labels of the nodes (negative values mean no label).

  • scores – Scores of the nodes (measure of importance).

  • membership – Membership of the nodes (label distribution).

  • seeds – Nodes to be highlighted (if dict, only keys are considered).

  • width – Width of the image.

  • height – Height of the image.

  • margin – Margin of the image.

  • margin_text – Margin between node and text.

  • scale – Multiplicative factor on the dimensions of the image.

  • node_order – Order in which nodes are displayed.

  • node_size – Size of nodes.

  • node_size_min – Minimum size of a node.

  • node_size_max – Maximum size of a node.

  • node_width – Width of node circle.

  • node_width_max – Maximum width of node circle.

  • node_color – Default color of nodes (svg color).

  • display_node_weight – If True, display node weights through node size.

  • node_weights – Node weights (used only if display_node_weight is True).

  • display_edges – If True, display edges.

  • edge_labels – Labels of the edges, as a list of tuples (source, destination, label)

  • edge_width – Width of edges.

  • edge_width_min – Minimum width of edges.

  • edge_width_max – Maximum width of edges.

  • display_edge_weight – If True, display edge weights through edge widths.

  • edge_color – Default color of edges (svg color).

  • label_colors – Colors of the labels (svg colors).

  • font_size – Font size.

  • directed – If True, considers the graph as directed.

  • filename – Filename for saving image (optional).

Returns

image – SVG image.

Return type

str

Example

>>> from sknetwork.data import karate_club
>>> graph = karate_club(True)
>>> adjacency = graph.adjacency
>>> position = graph.position
>>> from sknetwork.visualization import svg_graph
>>> image = svg_graph(adjacency, position)
>>> image[1:4]
'svg'
sknetwork.visualization.graphs.svg_digraph(adjacency: Optional[scipy.sparse.csr.csr_matrix] = None, position: Optional[numpy.ndarray] = None, names: Optional[numpy.ndarray] = None, labels: Optional[Iterable] = None, scores: Optional[Iterable] = None, membership: Optional[scipy.sparse.csr.csr_matrix] = None, seeds: Union[list, dict] = None, width: Optional[float] = 400, height: Optional[float] = 300, margin: float = 20, margin_text: float = 10, scale: float = 1, node_order: Optional[numpy.ndarray] = None, node_size: float = 7, node_size_min: float = 1, node_size_max: float = 20, display_node_weight: bool = False, node_weights: Optional[numpy.ndarray] = None, node_width: float = 1, node_width_max: float = 3, node_color: str = 'gray', display_edges: bool = True, edge_labels: Optional[list] = None, edge_width: float = 1, edge_width_min: float = 0.5, edge_width_max: float = 5, display_edge_weight: bool = True, edge_color: Optional[str] = None, label_colors: Optional[Iterable] = None, font_size: int = 12, filename: Optional[str] = None) → str[source]

Return SVG image of a digraph.

Parameters
  • adjacency – Adjacency matrix of the graph.

  • position – Positions of the nodes.

  • names – Names of the nodes.

  • labels – Labels of the nodes (negative values mean no label).

  • scores – Scores of the nodes (measure of importance).

  • membership – Membership of the nodes (label distribution).

  • seeds – Nodes to be highlighted (if dict, only keys are considered).

  • width – Width of the image.

  • height – Height of the image.

  • margin – Margin of the image.

  • margin_text – Margin between node and text.

  • scale – Multiplicative factor on the dimensions of the image.

  • node_order – Order in which nodes are displayed.

  • node_size – Size of nodes.

  • node_size_min – Minimum size of a node.

  • node_size_max – Maximum size of a node.

  • display_node_weight – If True, display node in-weights through node size.

  • node_weights – Node weights (used only if display_node_weight is True).

  • node_width – Width of node circle.

  • node_width_max – Maximum width of node circle.

  • node_color – Default color of nodes (svg color).

  • display_edges – If True, display edges.

  • edge_labels – Labels of the edges, as a list of tuples (source, destination, label)

  • edge_width – Width of edges.

  • edge_width_min – Minimum width of edges.

  • edge_width_max – Maximum width of edges.

  • display_edge_weight – If True, display edge weights through edge widths.

  • edge_color – Default color of edges (svg color).

  • label_colors – Colors of the labels (svg color).

  • font_size – Font size.

  • filename – Filename for saving image (optional).

Returns

image – SVG image.

Return type

str

Example

>>> from sknetwork.data import painters
>>> graph = painters(True)
>>> adjacency = graph.adjacency
>>> position = graph.position
>>> from sknetwork.visualization import svg_digraph
>>> image = svg_graph(adjacency, position)
>>> image[1:4]
'svg'
sknetwork.visualization.graphs.svg_bigraph(biadjacency: scipy.sparse.csr.csr_matrix, names_row: Optional[numpy.ndarray] = None, names_col: Optional[numpy.ndarray] = None, labels_row: Optional[Union[numpy.ndarray, dict]] = None, labels_col: Optional[Union[numpy.ndarray, dict]] = None, scores_row: Optional[Union[numpy.ndarray, dict]] = None, scores_col: Optional[Union[numpy.ndarray, dict]] = None, membership_row: Optional[scipy.sparse.csr.csr_matrix] = None, membership_col: Optional[scipy.sparse.csr.csr_matrix] = None, seeds_row: Union[list, dict] = None, seeds_col: Union[list, dict] = None, position_row: Optional[numpy.ndarray] = None, position_col: Optional[numpy.ndarray] = None, reorder: bool = True, width: Optional[float] = 400, height: Optional[float] = 300, margin: float = 20, margin_text: float = 3, scale: float = 1, node_size: float = 7, node_size_min: float = 1, node_size_max: float = 20, display_node_weight: bool = False, node_weights_row: Optional[numpy.ndarray] = None, node_weights_col: Optional[numpy.ndarray] = None, node_width: float = 1, node_width_max: float = 3, color_row: str = 'gray', color_col: str = 'gray', label_colors: Optional[Iterable] = None, display_edges: bool = True, edge_labels: Optional[list] = None, edge_width: float = 1, edge_width_min: float = 0.5, edge_width_max: float = 10, edge_color: str = 'black', display_edge_weight: bool = True, font_size: int = 12, filename: Optional[str] = None) → str[source]

Return SVG image of a bigraph.

Parameters
  • biadjacency – Biadjacency matrix of the graph.

  • names_row – Names of the rows.

  • names_col – Names of the columns.

  • labels_row – Labels of the rows (negative values mean no label).

  • labels_col – Labels of the columns (negative values mean no label).

  • scores_row – Scores of the rows (measure of importance).

  • scores_col – Scores of the columns (measure of importance).

  • membership_row – Membership of the rows (label distribution).

  • membership_col – Membership of the columns (label distribution).

  • seeds_row – Rows to be highlighted (if dict, only keys are considered).

  • seeds_col – Columns to be highlighted (if dict, only keys are considered).

  • position_row – Positions of the rows.

  • position_col – Positions of the columns.

  • reorder – Use clustering to order nodes.

  • width – Width of the image.

  • height – Height of the image.

  • margin – Margin of the image.

  • margin_text – Margin between node and text.

  • scale – Multiplicative factor on the dimensions of the image.

  • node_size – Size of nodes.

  • node_size_min – Minimum size of nodes.

  • node_size_max – Maximum size of nodes.

  • display_node_weight – If True, display node weights through node size.

  • node_weights_row – Weights of rows (used only if display_node_weight is True).

  • node_weights_col – Weights of columns (used only if display_node_weight is True).

  • node_width – Width of node circle.

  • node_width_max – Maximum width of node circle.

  • color_row – Default color of rows (svg color).

  • color_col – Default color of cols (svg color).

  • label_colors – Colors of the labels (svg color).

  • display_edges – If True, display edges.

  • edge_labels – Labels of the edges, as a list of tuples (source, destination, label)

  • edge_width – Width of edges.

  • edge_width_min – Minimum width of edges.

  • edge_width_max – Maximum width of edges.

  • display_edge_weight – If True, display edge weights through edge widths.

  • edge_color – Default color of edges (svg color).

  • font_size – Font size.

  • filename – Filename for saving image (optional).

Returns

image – SVG image.

Return type

str

Example

>>> from sknetwork.data import movie_actor
>>> biadjacency = movie_actor()
>>> from sknetwork.visualization import svg_bigraph
>>> image = svg_bigraph(biadjacency)
>>> image[1:4]
'svg'

Dendrograms

sknetwork.visualization.dendrograms.svg_dendrogram(dendrogram: numpy.ndarray, names: Optional[numpy.ndarray] = None, rotate: bool = False, width: float = 400, height: float = 300, margin: float = 10, margin_text: float = 5, scale: float = 1, line_width: float = 2, n_clusters: int = 2, color: str = 'black', colors: Optional[Iterable] = None, font_size: int = 12, reorder: bool = False, rotate_names: bool = True, filename: Optional[str] = None)[source]

Return SVG image of a dendrogram.

Parameters
  • dendrogram – Dendrogram to display.

  • names – Names of leaves.

  • rotate – If True, rotate the tree so that the root is on the left.

  • width – Width of the image (margins excluded).

  • height – Height of the image (margins excluded).

  • margin – Margin.

  • margin_text – Margin between leaves and their names, if any.

  • scale – Scaling factor.

  • line_width – Line width.

  • n_clusters – Number of coloured clusters to display.

  • color – Default SVG color for the dendrogram.

  • colors – SVG colors of the clusters of the dendrogram (optional).

  • font_size – Font size.

  • reorder – If True, reorder leaves so that left subtree has more leaves than right subtree.

  • rotate_names – If True, rotate names of leaves (only valid if rotate is False).

  • filename – Filename for saving image (optional).

Example

>>> dendrogram = np.array([[0, 1, 1, 2], [2, 3, 2, 3]])
>>> from sknetwork.visualization import svg_dendrogram
>>> image = svg_dendrogram(dendrogram)
>>> image[1:4]
'svg'