Skip to content

Visualization Module

Requires the viz extra (pip install "implicit-word-network[viz]").

implicit_word_network.visualization.plot_network

plot_network(network: ImplicitNetwork | Graph, *, min_weight: float = 0.0, top_k: int | None = 100, labels: Sequence[str] | None = None, label_order: Sequence[str] | None = None, min_component_size: int = 1, ax: Any | None = None, layout: str = 'spring', seed: int = 42, node_size: tuple[float, float] = (90.0, 1100.0), edge_width: tuple[float, float] = (0.6, 5.5), with_labels: bool = True, max_labels: int | None = None, font_size: float = 8.5, legend: bool = True, palette: Sequence[str] = CATEGORICAL_PALETTE, title: str | None = None, output_path: str | None = None, show: bool = False) -> Any

Draw the entity layer of a network with matplotlib.

Node area scales with the number of mentions, edge width and opacity with the edge weight, and node colour encodes the entity type (fixed hue per type, listed in a legend). Labels are set in text ink with a surface halo and nudged apart so they do not overlap. Isolated entities are not drawn.

PARAMETER DESCRIPTION
network

An ImplicitNetwork or a graph produced by to_networkx (node attributes text, label, count; edge weight).

TYPE: ImplicitNetwork | Graph

min_weight

Drop edges lighter than this (networks only).

TYPE: float DEFAULT: 0.0

top_k

Keep only the heaviest top_k edges (networks only; None keeps all).

TYPE: int | None DEFAULT: 100

labels

Restrict to these entity types (networks only).

TYPE: Sequence[str] | None DEFAULT: None

label_order

Entity types in the order they take palette slots. Defaults to types sorted by total mentions (most frequent first).

TYPE: Sequence[str] | None DEFAULT: None

min_component_size

Drop connected components with fewer nodes, so small satellites do not squeeze the main network into a corner.

TYPE: int DEFAULT: 1

ax

Matplotlib axes to draw on (a new figure is created otherwise).

TYPE: Any | None DEFAULT: None

layout

"spring", "kamada_kawai" or "circular".

TYPE: str DEFAULT: 'spring'

seed

Random seed of the spring layout.

TYPE: int DEFAULT: 42

node_size

Minimum and maximum node area in points².

TYPE: tuple[float, float] DEFAULT: (90.0, 1100.0)

edge_width

Minimum and maximum edge width in points.

TYPE: tuple[float, float] DEFAULT: (0.6, 5.5)

with_labels

Draw entity names.

TYPE: bool DEFAULT: True

max_labels

Label only the max_labels most mentioned entities.

TYPE: int | None DEFAULT: None

font_size

Label font size in points.

TYPE: float DEFAULT: 8.5

legend

Show the entity-type legend.

TYPE: bool DEFAULT: True

palette

Categorical colours, assigned to types in label_order.

TYPE: Sequence[str] DEFAULT: CATEGORICAL_PALETTE

title

Optional figure title.

TYPE: str | None DEFAULT: None

output_path

Save the figure to this path when given.

TYPE: str | None DEFAULT: None

show

Call plt.show().

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
Any

The matplotlib axes.