Visualization
Visualization tools.
Graphs
- sknetwork.visualization.graphs.svg_graph(adjacency: csr_matrix | None = None, position: ndarray | None = None, names: ndarray | None = None, labels: Iterable | None = None, name_position: str = 'right', scores: Iterable | None = None, probs: ndarray | csr_matrix | None = None, seeds: list | dict | None = None, width: float | None = 400, height: float | None = 300, margin: float = 20, margin_text: float = 3, scale: float = 1, node_order: ndarray | None = None, node_size: float = 7, node_size_min: float = 1, node_size_max: float = 20, display_node_weight: bool | None = None, node_weights: ndarray | None = None, node_width: float = 1, node_width_max: float = 3, node_color: str = 'gray', display_edges: bool = True, edge_labels: list | None = None, edge_width: float = 1, edge_width_min: float = 0.5, edge_width_max: float = 20, display_edge_weight: bool = True, edge_color: str | None = None, label_colors: Iterable | None = None, font_size: int = 12, directed: bool | None = None, filename: str | None = None) str [source]
Return the image of a graph in SVG format.
Alias for visualize_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).
name_position – Position of the names (left, right, above, below)
scores – Scores of the nodes (measure of importance).
probs – Probability distribution over labels.
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.
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
- sknetwork.visualization.graphs.visualize_bigraph(biadjacency: csr_matrix, names_row: ndarray | None = None, names_col: ndarray | None = None, labels_row: ndarray | dict | None = None, labels_col: ndarray | dict | None = None, scores_row: ndarray | dict | None = None, scores_col: ndarray | dict | None = None, probs_row: ndarray | csr_matrix | None = None, probs_col: ndarray | csr_matrix | None = None, seeds_row: list | dict | None = None, seeds_col: list | dict | None = None, position_row: ndarray | None = None, position_col: ndarray | None = None, reorder: bool = True, width: float | None = 400, height: float | None = 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: ndarray | None = None, node_weights_col: ndarray | None = None, node_width: float = 1, node_width_max: float = 3, color_row: str = 'gray', color_col: str = 'gray', label_colors: Iterable | None = None, display_edges: bool = True, edge_labels: list | None = 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: str | None = None) str [source]
Return the image of a bipartite graph in SVG format.
- 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).
probs_row – Probability distribution over labels for rows.
probs_col – Probability distribution over labels for columns.
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 visualize_bigraph >>> image = visualize_bigraph(biadjacency) >>> image[1:4] 'svg'
Dendrograms
- sknetwork.visualization.dendrograms.visualize_dendrogram(dendrogram: ndarray, names: ndarray | None = 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: Iterable | None = None, font_size: int = 12, reorder: bool = False, rotate_names: bool = True, filename: str | None = None)[source]
Return the image of a dendrogram in SVG format.
- 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 isFalse
).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'