Hive Plot Matrix#
A HivePlotMatrix is a grid of HivePlot instances for comparative network
visualization, analogous to a scatter plot matrix but for hive plots. It supports
both convenience methods for common use cases and a generic constructor.
Convenience Methods#
- classmethod HivePlotMatrix.from_partition(nodes: NodeCollection | None = None, edges: Edges | ndarray | None = None, *, graph: nx.Graph | None = None, partition_variable: Hashable, sorting_variables: Hashable | Dict[Hashable, Hashable], partition_values: List[Hashable] | None = None, collapsed_group_axis_name: str = 'Other', backend: Literal['matplotlib', 'datashader'] = 'matplotlib', include_diagonal: bool = True, hive_plot_kwargs: Dict | None = None, unify_axes: bool | Dict[Literal['vmin', 'vmax'], float] = False, axis_kwargs: dict | None = None, node_kwargs: dict | None = None, all_edge_kwargs: dict | None = None, repeat_edge_kwargs: dict | None = None, non_repeat_edge_kwargs: dict | None = None, clockwise_edge_kwargs: dict | None = None, counterclockwise_edge_kwargs: dict | None = None, num_steps_per_edge: int = 100, node_graph_metrics: str | Sequence[str] | None = None, edge_graph_metrics: str | Sequence[str] | None = None, node_graph_metric_kwargs: dict[str, dict] | None = None, edge_graph_metric_kwargs: dict[str, dict] | None = None, node_graph_metric_rename: dict[str, str] | None = None, edge_graph_metric_rename: dict[str, str] | None = None, graph_metric_backend: str | None = None, graph_directed: bool | None = None, graph_multigraph: bool | None = None, graph_source_attribute_name: str | None = None, warn_on_parallel_edge_collapse: bool = True, use_numba: bool = True, n_parallel: int | None = None, progress: bool = True) HivePlotMatrix#
Build a pairwise group matrix for networks with more than 3 groups.
Accepts either of two inputs: tabular data via the
nodes(ahiveplotlib.NodeCollection) andedges(ahiveplotlib.Edgesinstance or anumpy.ndarrayof(from, to)pairs), or a NetworkX graph via thegraphparameter.Providing both inputs (or partial inputs) raises a
ValueError.When the
graphparameter is provided,graph_directedandgraph_multigraphdefault tograph.is_directed()andgraph.is_multigraph()respectively. Whennodesandedgesare provided,graph_directeddefaults toTrueandgraph_multigraphdefaults toFalse. Explicit user values still win in either case. These resolved values are stashed on the resultingHivePlotMatrixand serve as the per-call defaults for any laterhiveplotlib.HivePlotMatrix.compute_graph_metrics()call, so a follow-up metric computation will use the same internal-graph type by default.Note
If you request graph metrics here (via
node_graph_metrics/edge_graph_metrics) or later viahiveplotlib.HivePlotMatrix.compute_graph_metrics(), an internalnetworkxgraph is rebuilt from the stored nodes / edges to compute them; an inputgraphis not reused. The conversion is typically cheap relative to the metrics themselves, but if you want to skip it entirely, attach the metrics as node / edge attributes ongraphbefore passing it (e.g.nx.set_node_attributes(graph, nx.betweenness_centrality(graph), "betweenness")). The converter carries those attributes through as columns on the resultinghiveplotlib.NodeCollection/hiveplotlib.Edges.Note
Parallel-edge collapse. When
graph_multigraph=False(the default fornodes/edgesinput) and the edge data has same-direction duplicate(from, to)rows, those rows collapse last-write-wins and aUserWarningis emitted (skip it withwarn_on_parallel_edge_collapse=False). Reciprocal(a, b)/(b, a)rows that merge only because an undirected build treats the pair symmetrically do not warn (that merge is the definitional meaning of the undirected metric). Either collapse keeps a single row’s attributes, so a metric given an edgeweightreflects only one of two differing reciprocal weights.graph_multigraph=Trueretains both edges only for metrics that accept multigraphs; metrics that require a simple graph (e.g.onion_layers) reject the multigraph, so for those pre-aggregate the reciprocal weights into a single edge before building.For N groups, creates an N x N upper-triangular matrix:
Diagonal (i, i): repeat axes for the single group.
Off-diagonal (i, j) where i < j: two named groups + collapsed “Other” axis.
Lower triangle: empty (
None).
- Parameters:
nodes – node data. Default
None; required whengraphis not provided. Mutually exclusive withgraph.edges – edge data corresponding to provided
nodes. If providing anumpy.ndarrayof edge data, must be provided as(from, to)pairs. Note, providing an array input does not support the inclusion of edge metadata, whereas theEdgesinstance input does. DefaultNone; required whengraphis not provided. Mutually exclusive withgraph.graph – input
networkxgraph (any ofGraph,DiGraph,MultiGraph, orMultiDiGraph) from which to construct the matrix. Mutually exclusive with thenodesandedgesparameters. DefaultNoneexpectsnodesandedgesto be provided instead. Distinct fromgraph_directed/graph_multigraph/graph_source_attribute_name, which configure the internalnetworkxgraph rebuilt for metric computation. To customize the conversion (e.g., override the unique-ID column name or skip the uniqueness check), callhiveplotlib.converters.networkx_to_nodes_edges()directly and pass the resultingnodesandedgesinstead.partition_variable – which column in node data to partition on. The unique values of this column define the groups compared in the matrix.
sorting_variables – which column(s) to sort nodes on each axis. Providing a single value uses the same variable for each axis. Alternatively, providing a dictionary of keys as the unique values from
partition_variablecolumn data and values being the corresponding sorting variable to use for that axis. Note when providing a dictionary input, _all_ keys for each axis created by the providedpartition_variablemust be specified (otherwise aMissingSortingVariableErrorwill be raised).partition_values – which partition values to include and their order. Default
Noneuses all unique values ofpartition_variable.collapsed_group_axis_name – name for the collapsed “Other” axis. Default
"Other".backend – visualization backend. Default
"matplotlib".include_diagonal – whether to include diagonal (repeat-axis) cells. Default
True.hive_plot_kwargs – additional keyword arguments passed to each
HivePlotconstructor.unify_axes –
whether to unify axis value ranges across all cells. When
True, auto-computes globalvmin/vmaxfrom the node data and applies them uniformly. When adict(e.g.{"vmin": 0, "vmax": 10}or{"vmin": 0}), uses explicit values and auto-computes any missing ones. WhenFalse(default), axes auto-scale per cell. Pre-computed from the raw data to avoid a double build.Priority of params:
axis_kwargs> explicit dict values > auto-computed values.axis_kwargs – keyword arguments applied uniformly to every axis in every hive plot cell (e.g.
{"vmin": 0, "vmax": 1e9}to fix the display range across all axes). Takes precedence over any"axis_kwargs"key insidehive_plot_kwargs.node_kwargs – keyword arguments forwarded to the node rendering call for every hive plot cell. For the
matplotlibbackend these arescatter()kwargs; for thedatashaderbackend these areimshow()kwargs applied to the node rasterization. Can be overridden at plot time by passingnode_kwargsdirectly toplot().all_edge_kwargs – keyword arguments for all edges. Disregarded when using the
"datashader"backend.repeat_edge_kwargs – keyword arguments for repeat edges (diagonal cells). Disregarded when using the
"datashader"backend.non_repeat_edge_kwargs – keyword arguments for non-repeat edges (off-diagonal cells). Disregarded when using the
"datashader"backend.clockwise_edge_kwargs – keyword arguments for edges going clockwise (off-diagonal cells only). Disregarded when using the
"datashader"backend.counterclockwise_edge_kwargs – keyword arguments for edges going counterclockwise (off-diagonal cells only). Disregarded when using the
"datashader"backend.num_steps_per_edge – number of Bezier curve steps per edge.
node_graph_metrics – optional node graph-metric string name (or sequence of names) to compute and attach as columns to
nodesbefore any sub-plot is constructed. Each name must be a key inhiveplotlib.graph_features.GRAPH_NODE_METRICS. Computed once on the underlyingnodes/edges(seegraph_directed/graph_multigraph) and the augmented columns are then available aspartition_variable/sorting_variables. DefaultNoneskips computing any metrics.edge_graph_metrics – optional edge graph-metric string name (or sequence of names) to compute and attach as columns to
edges. Each name must be a key inhiveplotlib.graph_features.GRAPH_EDGE_METRICS. DefaultNoneskips computing any metrics.node_graph_metric_kwargs – per-metric
**kwargsto forward to each node-metric wrapper, keyed by metric name (e.g.{"betweenness_centrality": {"normalized": False}}).edge_graph_metric_kwargs – per-metric
**kwargsto forward to each edge-metric wrapper, keyed by metric name (e.g.{"edge_betweenness_centrality": {"normalized": False}}).node_graph_metric_rename – per-metric override mapping from metric name to the column name used on the resulting
hiveplotlib.NodeCollection. Useful for resolving collisions when a metric name already exists as a column.edge_graph_metric_rename – same as
node_graph_metric_renamebut for edge metrics.graph_metric_backend – name of a
networkxdispatchable backend on which to compute any requested graph metrics. DefaultNonecomputes everything on default networkx. The value is stored on the resultingHivePlotMatrixand serves as the default for laterhiveplotlib.HivePlotMatrix.compute_graph_metrics()calls (see that method for the full precedence chain).degree,in_degree, andout_degreeare direct structural reads of the graph, so backend dispatch does not apply to them (the result is identical either way). See the parameter of the same name onHivePlotMatrixandhiveplotlib.graph_features.compute_graph_metrics()for backend-name validation and fallback behavior.graph_directed – directionality of the internal
networkxgraph used for metric computation only; it does not affect how any hive plot cell is rendered. An explicitTrue/Falsealways wins, and if that value conflicts with a requested metric’s requirement aValueErroris raised. WhatNone(the default) does depends on how the matrix is built. From ``nodes`` / ``edges``: the value is inferred when every requested metric that cares about directedness agrees, sonode_graph_metrics="triangles"builds an undirected internal graph without setting the flag; with no such metric it defaults toTrue, matching the(from, to)semantics ofhiveplotlib.Edges. A requested set that is itself contradictory (one metric needs a directed graph, another an undirected one) cannot be inferred and raises the same conflictValueError. From ``graph``: the value is taken from the input graph (graph.is_directed()) and is not inferred from your metrics, so the graph you passed keeps its own type; if a requested metric needs the opposite (e.g.triangleson a directed graph), you get the conflictValueErrorrather than a silent re-typing, so pass an explicitgraph_directedor convert the graph first (e.g.graph.to_undirected()).graph_multigraph – unlike
graph_directed, this is never inferred from the requested metrics. It controls whether each row in yourhiveplotlib.Edgescounts as a distinct edge when metrics are computed (across all tags for multi-tag inputs); it does not affect how any hive plot cell is rendered. PassingTruetogether with a metric that rejects multigraphs raises aValueError. WhatNone(the default) does depends on how the matrix is built. From ``nodes`` / ``edges``: defaults toFalse, collapsing repeated(from, to)rows into a single edge in the internal graph; setTrueto keep them distinct. From ``graph``: defaults to the input graph’s own type (graph.is_multigraph()), so the graph you passed keeps its multi-edge structure. See the note on parallel-edge collapse in this method’s description.graph_source_attribute_name – edge-attribute name used internally to map each metric value computed on a repeated edge back to its specific source row when
graph_multigraph=True. DefaultNoneresolves to"_hiveplotlib_source", which works for nearly all use cases; override only if it collides with an existing edge column.warn_on_parallel_edge_collapse – whether to detect and warn about same-direction duplicate
(from, to)edges collapsing during metric computation. DefaultTrue. SettingFalseskips the detection entirely (a performance escape hatch for large graphs); it does not change whether edges collapse (duplicates are still merged last-write-wins). To preserve parallel edges instead, usegraph_multigraph=True.use_numba – whether to use numba for Bezier computation.
n_parallel – number of parallel threads for Bezier computation.
progress – whether to show a progress bar.
- Raises:
ValueError – if both
graphand thenodesandedgesparameters are provided, if no input is provided, or if only one ofnodes/edgesis provided.ValueError – if the requested
node_graph_metrics/edge_graph_metricshave irreconcilable graph-type requirements for the single internal graph: a directedness standoff (one metric needs a directed graph, another an undirected one, caught across the node/edge boundary since they share one graph), or an explicitgraph_directed/graph_multigraphvalue that conflicts with a requested metric. Raised up front, before any metric runs. Resolve a standoff by building two matrices, one pergraph_directed.InvalidGraphMetricBackendError – if graph metrics are requested and
graph_metric_backend(or a per-metric"backend"entry innode_graph_metric_kwargs/edge_graph_metric_kwargs) is not an installednetworkxdispatchable backend, targetsdegree/in_degree/out_degree, or is requested onnetworkx<3.2. Raised up front, before any metric runs; seehiveplotlib.graph_features.compute_graph_metrics().
- Returns:
HivePlotMatrixinstance.
- classmethod HivePlotMatrix.from_variable_sweep(nodes: NodeCollection | None = None, edges: Edges | ndarray | None = None, *, graph: nx.Graph | None = None, partition_variable: Hashable | None = None, sorting_variables: Hashable | Dict[Hashable, Hashable] | None = None, sorting_variables_list: List[Hashable | Dict[Hashable, Hashable]] | None = None, partition_variables_list: List[Hashable] | None = None, repeat_axes: bool | Hashable | List[Hashable] = False, ncols: int | None = None, backend: Literal['matplotlib', 'datashader'] = 'matplotlib', hive_plot_kwargs: Dict | None = None, unify_axes: bool | Dict[Literal['vmin', 'vmax'], float] = False, axis_kwargs: dict | None = None, node_kwargs: dict | None = None, all_edge_kwargs: dict | None = None, repeat_edge_kwargs: dict | None = None, non_repeat_edge_kwargs: dict | None = None, clockwise_edge_kwargs: dict | None = None, counterclockwise_edge_kwargs: dict | None = None, num_steps_per_edge: int = 100, node_graph_metrics: str | Sequence[str] | None = None, edge_graph_metrics: str | Sequence[str] | None = None, node_graph_metric_kwargs: dict[str, dict] | None = None, edge_graph_metric_kwargs: dict[str, dict] | None = None, node_graph_metric_rename: dict[str, str] | None = None, edge_graph_metric_rename: dict[str, str] | None = None, graph_metric_backend: str | None = None, graph_directed: bool | None = None, graph_multigraph: bool | None = None, graph_source_attribute_name: str | None = None, warn_on_parallel_edge_collapse: bool = True, use_numba: bool = True, n_parallel: int | None = None, progress: bool = True) HivePlotMatrix#
Build a matrix comparing different sorting and/or partition variables.
Accepts either of two inputs: tabular data via the
nodes(ahiveplotlib.NodeCollection) andedges(ahiveplotlib.Edgesinstance or anumpy.ndarrayof(from, to)pairs), or a NetworkX graph via thegraphparameter.Providing both inputs (or partial inputs) raises a
ValueError.When the
graphparameter is provided,graph_directedandgraph_multigraphdefault tograph.is_directed()andgraph.is_multigraph()respectively. Whennodesandedgesare provided,graph_directeddefaults toTrueandgraph_multigraphdefaults toFalse. Explicit user values still win in either case. These resolved values are stashed on the resultingHivePlotMatrixand serve as the per-call defaults for any laterhiveplotlib.HivePlotMatrix.compute_graph_metrics()call, so a follow-up metric computation will use the same internal-graph type by default.Note
If you request graph metrics here (via
node_graph_metrics/edge_graph_metrics) or later viahiveplotlib.HivePlotMatrix.compute_graph_metrics(), an internalnetworkxgraph is rebuilt from the stored nodes / edges to compute them; an inputgraphis not reused. The conversion is typically cheap relative to the metrics themselves, but if you want to skip it entirely, attach the metrics as node / edge attributes ongraphbefore passing it (e.g.nx.set_node_attributes(graph, nx.betweenness_centrality(graph), "betweenness")). The converter carries those attributes through as columns on the resultinghiveplotlib.NodeCollection/hiveplotlib.Edges.Note
Parallel-edge collapse. When
graph_multigraph=False(the default fornodes/edgesinput) and the edge data has same-direction duplicate(from, to)rows, those rows collapse last-write-wins and aUserWarningis emitted (skip it withwarn_on_parallel_edge_collapse=False). Reciprocal(a, b)/(b, a)rows that merge only because an undirected build treats the pair symmetrically do not warn (that merge is the definitional meaning of the undirected metric). Either collapse keeps a single row’s attributes, so a metric given an edgeweightreflects only one of two differing reciprocal weights.graph_multigraph=Trueretains both edges only for metrics that accept multigraphs; metrics that require a simple graph (e.g.onion_layers) reject the multigraph, so for those pre-aggregate the reciprocal weights into a single edge before building.Three modes based on which list parameters are provided:
sorting_variables_listonly: 1D row, each column uses a different sorting variable (requirespartition_variable)partition_variables_listonly: 1D row, each column uses a different partition variable (requiressorting_variables)Both: 2D grid with rows = partition variables, columns = sorting variables
- Parameters:
nodes – node data. Default
None; required whengraphis not provided. Mutually exclusive withgraph.edges – edge data corresponding to provided
nodes. If providing anumpy.ndarrayof edge data, must be provided as(from, to)pairs. Note, providing an array input does not support the inclusion of edge metadata, whereas theEdgesinstance input does. DefaultNone; required whengraphis not provided. Mutually exclusive withgraph.graph – input
networkxgraph (any ofGraph,DiGraph,MultiGraph, orMultiDiGraph) from which to construct the matrix. Mutually exclusive with thenodesandedgesparameters. DefaultNoneexpectsnodesandedgesto be provided instead. Distinct fromgraph_directed/graph_multigraph/graph_source_attribute_name, which configure the internalnetworkxgraph rebuilt for metric computation. To customize the conversion (e.g., override the unique-ID column name or skip the uniqueness check), callhiveplotlib.converters.networkx_to_nodes_edges()directly and pass the resultingnodesandedgesinstead.partition_variable – fixed partition variable (required when only
partition_variables_listis not provided).sorting_variables – fixed sorting variable(s) (required when only
sorting_variables_listis not provided).sorting_variables_list – list of sorting variable configurations to compare.
partition_variables_list – list of partition variables to compare.
repeat_axes – which partition groups to create repeat axes for.
Truecreates repeat axes for all groups,Falsedisables repeat axes. Whenpartition_variables_listis provided, onlyTrue/Falseis accepted (specific axis names vary across partition variables).ncols – when result is 1D, wrap into rows of
ncolswidth. Ignored when both lists are provided.backend – visualization backend.
hive_plot_kwargs – additional keyword arguments passed to each
HivePlotconstructor.unify_axes –
whether to unify axis value ranges across all cells. When
True, auto-computes globalvmin/vmaxfrom the node data across all sorting variables and applies them uniformly. When adict(e.g.{"vmin": 0, "vmax": 10}or{"vmin": 0}), uses explicit values and auto-computes any missing ones. WhenFalse(default), axes auto-scale per cell.Priority of params:
axis_kwargs> explicit dict values > auto-computed values.axis_kwargs – keyword arguments applied uniformly to every axis in every hive plot cell (e.g.
{"vmin": 0, "vmax": 1e9}to fix the display range across all axes). Takes precedence over any"axis_kwargs"key insidehive_plot_kwargs.node_kwargs – keyword arguments forwarded to the node rendering call for every hive plot cell. For the
matplotlibbackend these arescatter()kwargs; for thedatashaderbackend these areimshow()kwargs applied to the node rasterization. Can be overridden at plot time by passingnode_kwargsdirectly toplot().all_edge_kwargs – keyword arguments for all edges. Disregarded when using the
"datashader"backend.repeat_edge_kwargs – keyword arguments for repeat edges. Disregarded when using the
"datashader"backend.non_repeat_edge_kwargs – keyword arguments for non-repeat edges. Disregarded when using the
"datashader"backend.clockwise_edge_kwargs – keyword arguments for edges going clockwise. Disregarded when using the
"datashader"backend.counterclockwise_edge_kwargs – keyword arguments for edges going counterclockwise. Disregarded when using the
"datashader"backend.num_steps_per_edge – number of Bezier curve steps per edge.
node_graph_metrics – optional node graph-metric string name (or sequence of names) to compute and attach as columns to
nodesbefore any sub-plot is constructed. Each name must be a key inhiveplotlib.graph_features.GRAPH_NODE_METRICS. Computed once on the underlyingnodes/edges(seegraph_directed/graph_multigraph) and the augmented columns are then available aspartition_variable/sorting_variables/partition_variables_list/sorting_variables_listentries. DefaultNoneskips computing any metrics.edge_graph_metrics – optional edge graph-metric string name (or sequence of names) to compute and attach as columns to
edges. Each name must be a key inhiveplotlib.graph_features.GRAPH_EDGE_METRICS. DefaultNoneskips computing any metrics.node_graph_metric_kwargs – per-metric
**kwargsto forward to each node-metric wrapper, keyed by metric name (e.g.{"betweenness_centrality": {"normalized": False}}).edge_graph_metric_kwargs – per-metric
**kwargsto forward to each edge-metric wrapper, keyed by metric name (e.g.{"edge_betweenness_centrality": {"normalized": False}}).node_graph_metric_rename – per-metric override mapping from metric name to the column name used on the resulting
hiveplotlib.NodeCollection. Useful for resolving collisions when a metric name already exists as a column.edge_graph_metric_rename – same as
node_graph_metric_renamebut for edge metrics.graph_metric_backend – name of a
networkxdispatchable backend on which to compute any requested graph metrics. DefaultNonecomputes everything on default networkx. The value is stored on the resultingHivePlotMatrixand serves as the default for laterhiveplotlib.HivePlotMatrix.compute_graph_metrics()calls (see that method for the full precedence chain).degree,in_degree, andout_degreeare direct structural reads of the graph, so backend dispatch does not apply to them (the result is identical either way). See the parameter of the same name onHivePlotMatrixandhiveplotlib.graph_features.compute_graph_metrics()for backend-name validation and fallback behavior.graph_directed – directionality of the internal
networkxgraph used for metric computation only; it does not affect how any hive plot cell is rendered. An explicitTrue/Falsealways wins, and if that value conflicts with a requested metric’s requirement aValueErroris raised. WhatNone(the default) does depends on how the matrix is built. From ``nodes`` / ``edges``: the value is inferred when every requested metric that cares about directedness agrees, sonode_graph_metrics="triangles"builds an undirected internal graph without setting the flag; with no such metric it defaults toTrue, matching the(from, to)semantics ofhiveplotlib.Edges. A requested set that is itself contradictory (one metric needs a directed graph, another an undirected one) cannot be inferred and raises the same conflictValueError. From ``graph``: the value is taken from the input graph (graph.is_directed()) and is not inferred from your metrics, so the graph you passed keeps its own type; if a requested metric needs the opposite (e.g.triangleson a directed graph), you get the conflictValueErrorrather than a silent re-typing, so pass an explicitgraph_directedor convert the graph first (e.g.graph.to_undirected()).graph_multigraph – unlike
graph_directed, this is never inferred from the requested metrics. It controls whether each row in yourhiveplotlib.Edgescounts as a distinct edge when metrics are computed (across all tags for multi-tag inputs); it does not affect how any hive plot cell is rendered. PassingTruetogether with a metric that rejects multigraphs raises aValueError. WhatNone(the default) does depends on how the matrix is built. From ``nodes`` / ``edges``: defaults toFalse, collapsing repeated(from, to)rows into a single edge in the internal graph; setTrueto keep them distinct. From ``graph``: defaults to the input graph’s own type (graph.is_multigraph()), so the graph you passed keeps its multi-edge structure. See the note on parallel-edge collapse in this method’s description.graph_source_attribute_name – edge-attribute name used internally to map each metric value computed on a repeated edge back to its specific source row when
graph_multigraph=True. DefaultNoneresolves to"_hiveplotlib_source", which works for nearly all use cases; override only if it collides with an existing edge column.warn_on_parallel_edge_collapse – whether to detect and warn about same-direction duplicate
(from, to)edges collapsing during metric computation. DefaultTrue. SettingFalseskips the detection entirely (a performance escape hatch for large graphs); it does not change whether edges collapse (duplicates are still merged last-write-wins). To preserve parallel edges instead, usegraph_multigraph=True.use_numba – whether to use numba for Bezier computation.
n_parallel – number of parallel threads for Bezier computation.
progress – whether to show a progress bar.
- Raises:
ValueError – if both
graphand thenodesandedgesparameters are provided, if no input is provided, or if only one ofnodes/edgesis provided.ValueError – if the requested
node_graph_metrics/edge_graph_metricshave irreconcilable graph-type requirements for the single internal graph: a directedness standoff (one metric needs a directed graph, another an undirected one, caught across the node/edge boundary since they share one graph), or an explicitgraph_directed/graph_multigraphvalue that conflicts with a requested metric. Raised up front, before any metric runs. Resolve a standoff by building two matrices, one pergraph_directed.InvalidGraphMetricBackendError – if graph metrics are requested and
graph_metric_backend(or a per-metric"backend"entry innode_graph_metric_kwargs/edge_graph_metric_kwargs) is not an installednetworkxdispatchable backend, targetsdegree/in_degree/out_degree, or is requested onnetworkx<3.2. Raised up front, before any metric runs; seehiveplotlib.graph_features.compute_graph_metrics().
- Returns:
HivePlotMatrixinstance.
- classmethod HivePlotMatrix.from_tags(nodes: NodeCollection, edges: Edges | ndarray, *, partition_variable: Hashable, sorting_variables: Hashable | Dict[Hashable, Hashable], tags: List[Hashable] | None = None, repeat_axes: bool | Hashable | List[Hashable] = False, ncols: int | None = None, backend: Literal['matplotlib', 'datashader'] = 'matplotlib', hive_plot_kwargs: Dict | None = None, unify_axes: bool | Dict[Literal['vmin', 'vmax'], float] = False, axis_kwargs: dict | None = None, node_kwargs: dict | None = None, per_tag_plot_kwargs: Dict[Hashable, dict] | None = None, all_edge_kwargs: dict | None = None, repeat_edge_kwargs: dict | None = None, non_repeat_edge_kwargs: dict | None = None, clockwise_edge_kwargs: dict | None = None, counterclockwise_edge_kwargs: dict | None = None, num_steps_per_edge: int = 100, node_graph_metrics: str | Sequence[str] | None = None, edge_graph_metrics: str | Sequence[str] | None = None, node_graph_metric_kwargs: dict[str, dict] | None = None, edge_graph_metric_kwargs: dict[str, dict] | None = None, node_graph_metric_rename: dict[str, str] | None = None, edge_graph_metric_rename: dict[str, str] | None = None, graph_metric_backend: str | None = None, graph_directed: bool = True, graph_multigraph: bool = False, graph_source_attribute_name: str = '_hiveplotlib_source', warn_on_parallel_edge_collapse: bool = True, use_numba: bool = True, n_parallel: int | None = None) HivePlotMatrix#
Build a matrix comparing different edge tags side by side.
Each cell shows the same nodes and axis layout rendered with a different edge tag. Node positions are identical across all cells, only the visible edges change.
This method is the right choice when your tags represent different relationship types on the same network (e.g.,
"official","social","informal"edges among the same set of people).Note
Unlike
hiveplotlib.HivePlotMatrix.from_partition()andhiveplotlib.HivePlotMatrix.from_variable_sweep(), this classmethod does not accept anetworkxgraph directly. Tags are a property of thehiveplotlib.Edgesobject, not of the input graph: a user callingfrom_tagshas already classified their edges into named groups (the keys onedges._data) before construction.Users with a
networkxgraph need to assemble multi-tagEdgesfrom a graph manually, converting viahiveplotlib.converters.networkx_to_nodes_edges()and split the resulting single-tagEdgesinto the desired tag buckets, then passEdges(data={tag: df, ...})tofrom_tags.The
graph_directed,graph_multigraph, andgraph_source_attribute_namevalues you pass here are stashed on the resultingHivePlotMatrixand serve as the per-call defaults for any laterhiveplotlib.HivePlotMatrix.compute_graph_metrics()call, so a follow-up metric computation will use the same internal-graph type by default.Note
If you request graph metrics here (via
node_graph_metrics/edge_graph_metrics) or later viahiveplotlib.HivePlotMatrix.compute_graph_metrics(), an internalnetworkxgraph is rebuilt from the stored nodes / edges to compute them. The conversion is typically cheap relative to the metrics themselves; if you want to skip it entirely, attach the metrics as node / edge attributes on your data before construction (e.g.nx.set_node_attributes(graph, nx.betweenness_centrality(graph), "betweenness"), then convert viahiveplotlib.converters.networkx_to_nodes_edges()). The converter carries those attributes through as columns on the resultinghiveplotlib.NodeCollection/hiveplotlib.Edges.Note
Parallel-edge collapse. When
graph_multigraph=False(the default fornodes/edgesinput) and the edge data has same-direction duplicate(from, to)rows, those rows collapse last-write-wins and aUserWarningis emitted (skip it withwarn_on_parallel_edge_collapse=False). Reciprocal(a, b)/(b, a)rows that merge only because an undirected build treats the pair symmetrically do not warn (that merge is the definitional meaning of the undirected metric). Either collapse keeps a single row’s attributes, so a metric given an edgeweightreflects only one of two differing reciprocal weights.graph_multigraph=Trueretains both edges only for metrics that accept multigraphs; metrics that require a simple graph (e.g.onion_layers) reject the multigraph, so for those pre-aggregate the reciprocal weights into a single edge before building.Warning
When NOT to use
from_tags: if your tags correspond to fundamentally different network snapshots (such as different time periods where the set of active nodes changes, or where per-tag node attributes differ meaningfully), thenfrom_tagsis the wrong tool. All cells will show the fullNodeCollectionregardless of which nodes actually appear in each tag’s edges, and node positions will be based on the pooled data, not per-tag data.For per-snapshot comparisons (e.g., year-by-year network evolution), build a separate
HivePlotper snapshot and pass the resulting list to the genericHivePlotMatrixconstructor.- Parameters:
nodes – node data. Shared across all cells.
edges – edge data corresponding to provided
nodes. If providing anumpy.ndarrayof edge data, must be provided as(from, to)pairs. Note, providing an array input does not support the inclusion of edge metadata, whereas theEdgesinstance input does.partition_variable – which column in node data to partition on.
sorting_variables – which column(s) to sort nodes on each axis. Providing a single value uses the same variable for each axis. Alternatively, providing a dictionary of keys as the unique values from
partition_variablecolumn data and values being the corresponding sorting variable to use for that axis. Note when providing a dictionary input, _all_ keys for each axis created by the providedpartition_variablemust be specified (otherwise aMissingSortingVariableErrorwill be raised).tags – which edge tags to compare. Default
Noneuses all tags from the edges.repeat_axes – which partition groups to create repeat axes for.
Truecreates repeat axes for all groups,Falsedisables repeat axes.ncols – when provided, wraps the 1D row into rows of
ncolswidth.backend – visualization backend.
hive_plot_kwargs – additional keyword arguments passed to each
HivePlotconstructor.unify_axes –
whether to unify axis value ranges across all cells. When
True, auto-computes a single globalvmin/vmaxacross all sorting variables and applies them uniformly to every axis. Since different axes correspond to different partition groups, they may naturally have different data ranges;Truecollapses these into one shared range. When adict(e.g.{"vmin": 0, "vmax": 10}), uses explicit values and auto-computes any missing ones. WhenFalse(default), each axis auto-scales to its own data range.Priority of params:
axis_kwargs> explicit dict values > auto-computed values.axis_kwargs – keyword arguments applied uniformly to every axis in every hive plot cell (e.g.
{"vmin": 0, "vmax": 1e9}to fix the display range across all axes). Because all hive plot cells share the samepartition_variable, the same kwargs are applied to every axis in every cell. Takes precedence over any"axis_kwargs"key insidehive_plot_kwargs.node_kwargs – keyword arguments forwarded to the node rendering call for every hive plot cell. For the
matplotlibbackend these arescatter()kwargs; for thedatashaderbackend these areimshow()kwargs applied to the node rasterization. Can be overridden at plot time by passingnode_kwargsdirectly toplot().per_tag_plot_kwargs – per-tag keyword arguments forwarded to each hive plot cell’s plot call (e.g.
{"Older": {"cmap_edges": "Blues"}, "Newer": {"cmap_edges": "Oranges"}}). Stored on the instance; can be overridden at plot time viaper_tag_kwargsonplot(). Works for both thematplotlibanddatashaderbackends; any plot-time kwarg accepted by the hive plot cell renderer can be supplied. The primarydatashaderuse case is per-tagcmap_edges.all_edge_kwargs – keyword arguments for all edges. Disregarded when using the
"datashader"backend.repeat_edge_kwargs – keyword arguments for repeat edges. Disregarded when using the
"datashader"backend.non_repeat_edge_kwargs – keyword arguments for non-repeat edges. Disregarded when using the
"datashader"backend.clockwise_edge_kwargs – keyword arguments for edges going clockwise. Disregarded when using the
"datashader"backend.counterclockwise_edge_kwargs – keyword arguments for edges going counterclockwise. Disregarded when using the
"datashader"backend.num_steps_per_edge – number of Bezier curve steps per edge.
node_graph_metrics – optional node graph-metric string name (or sequence of names) to compute and attach as columns to
nodesbefore any sub-plot is constructed. Each name must be a key inhiveplotlib.graph_features.GRAPH_NODE_METRICS. Computed once on the underlyingnodes/edges(across all tags; seegraph_directed/graph_multigraph) and the augmented columns are then available aspartition_variable/sorting_variables. DefaultNoneskips computing any metrics.edge_graph_metrics – optional edge graph-metric string name (or sequence of names) to compute and attach as columns to
edges. Each name must be a key inhiveplotlib.graph_features.GRAPH_EDGE_METRICS. DefaultNoneskips computing any metrics.node_graph_metric_kwargs – per-metric
**kwargsto forward to each node-metric wrapper, keyed by metric name (e.g.{"betweenness_centrality": {"normalized": False}}).edge_graph_metric_kwargs – per-metric
**kwargsto forward to each edge-metric wrapper, keyed by metric name (e.g.{"edge_betweenness_centrality": {"normalized": False}}).node_graph_metric_rename – per-metric override mapping from metric name to the column name used on the resulting
hiveplotlib.NodeCollection. Useful for resolving collisions when a metric name already exists as a column.edge_graph_metric_rename – same as
node_graph_metric_renamebut for edge metrics.graph_metric_backend – name of a
networkxdispatchable backend on which to compute any requested graph metrics. DefaultNonecomputes everything on default networkx. The value is stored on the resultingHivePlotMatrixand serves as the default for laterhiveplotlib.HivePlotMatrix.compute_graph_metrics()calls (see that method for the full precedence chain).degree,in_degree, andout_degreeare direct structural reads of the graph, so backend dispatch does not apply to them (the result is identical either way). See the parameter of the same name onHivePlotMatrixandhiveplotlib.graph_features.compute_graph_metrics()for backend-name validation and fallback behavior.graph_directed – this constructor fixes directedness to whatever you pass and never infers it from the requested metrics; use
from_partition()orfrom_variable_sweep()if you want directedness inferred from the metric set. It sets the directionality of the internalnetworkxgraph used for metric computation; it does not affect how any hive plot cell is rendered. Directedness defaults toTrue, matching the(from, to)semantics ofhiveplotlib.Edges, so an undirected-only metric liketrianglesneeds an explicitgraph_directed=Falsehere. A requested set with both a directed-required and an undirected-required metric, or an explicitgraph_directedthat conflicts with a requested metric, raises aValueError.graph_multigraph – unlike
graph_directed, this is never inferred from the requested metrics. It controls whether each row in yourhiveplotlib.Edgescounts as a distinct edge when metrics are computed (across all tags for multi-tag inputs); it does not affect how any hive plot cell is rendered. Defaults toFalse, collapsing repeated(from, to)rows into a single edge in the internal graph; setTrueto keep them distinct. PassingTruewith a metric that rejects multigraphs raises aValueError. See the note on parallel-edge collapse above.graph_source_attribute_name – edge-attribute name used internally to map each metric value computed on a repeated edge back to its specific source row when
graph_multigraph=True. Defaults to"_hiveplotlib_source", which works for nearly all use cases; override only if it collides with an existing edge column.warn_on_parallel_edge_collapse – whether to detect and warn about same-direction duplicate
(from, to)edges collapsing during metric computation. DefaultTrue. SettingFalseskips the detection entirely (a performance escape hatch for large graphs); it does not change whether edges collapse (duplicates are still merged last-write-wins). To preserve parallel edges instead, usegraph_multigraph=True.use_numba – whether to use numba for Bezier computation.
n_parallel – number of parallel threads for Bezier computation.
- Raises:
ValueError – if the requested
node_graph_metrics/edge_graph_metricshave irreconcilable graph-type requirements for the single internal graph: a directedness standoff (one metric needs a directed graph, another an undirected one, caught across the node/edge boundary since they share one graph), or agraph_directed/graph_multigraphvalue that conflicts with a requested metric. Raised up front, before any metric runs. Resolve a standoff by building two matrices, one pergraph_directedvalue.InvalidGraphMetricBackendError – if graph metrics are requested and
graph_metric_backend(or a per-metric"backend"entry innode_graph_metric_kwargs/edge_graph_metric_kwargs) is not an installednetworkxdispatchable backend, targetsdegree/in_degree/out_degree, or is requested onnetworkx<3.2. Raised up front, before any metric runs; seehiveplotlib.graph_features.compute_graph_metrics().
- Returns:
HivePlotMatrixinstance.
Generic Constructor#
The generic constructor accepts a list-of-lists or dictionary of HivePlot instances.
For common patterns, use the convenience methods above.
- class hiveplotlib.HivePlotMatrix(hive_plots: List[List[HivePlot | None]] | Dict[Tuple[int, int], HivePlot], row_labels: List[Hashable] | None = None, col_labels: List[Hashable] | None = None, backend: Literal['matplotlib', 'datashader'] | None = None, unify_axes: bool | Dict[str, float] = False, axis_kwargs: dict | None = None, node_kwargs: dict | None = None, all_edge_kwargs: dict | None = None, repeat_edge_kwargs: dict | None = None, non_repeat_edge_kwargs: dict | None = None, clockwise_edge_kwargs: dict | None = None, counterclockwise_edge_kwargs: dict | None = None, node_graph_metrics: str | Sequence[str] | None = None, edge_graph_metrics: str | Sequence[str] | None = None, node_graph_metric_kwargs: dict[str, dict] | None = None, edge_graph_metric_kwargs: dict[str, dict] | None = None, node_graph_metric_rename: dict[str, str] | None = None, edge_graph_metric_rename: dict[str, str] | None = None, graph_metric_backend: str | None = None, graph_directed: bool = True, graph_multigraph: bool = False, graph_source_attribute_name: str = '_hiveplotlib_source', warn_on_parallel_edge_collapse: bool = True)#
Matrix of
HivePlotinstances for comparative network visualization.A
HivePlotMatrixstores a 2D grid ofHivePlotinstances (orNonefor empty cells), along with optional row and column labels. This class provides both a generic constructor and convenience methods for common use cases.The generic constructor accepts a list-of-lists or dictionary of
HivePlotinstances. For common patterns, use the convenience methods:from_partition(): pairwise group matrix for networks with >3 groups.from_variable_sweep(): compare different sorting and/or partition variables.from_tags(): compare different edge tags side by side.
- Parameters:
hive_plots – 2D grid of
HivePlotinstances. Can be provided as a list of lists (where inner lists are rows andNonerepresents empty cells) or as a dictionary mapping(row, col)tuples toHivePlotinstances.row_labels – labels for each row. Length must match the number of rows.
col_labels – labels for each column. Length must match the number of columns.
backend – visualization backend to use. When provided, sets the backend on all populated cells. When
None(default), the backend is inferred from the first populated hive plot cell.unify_axes –
whether to unify axis value ranges across all cells. When
True, auto-computes globalvmin/vmaxfrom all axes in all hive plots and applies them uniformly. When adict(e.g.{"vmin": 0, "vmax": 10}or{"vmin": 0}), uses explicit values and auto-computes any missing ones. WhenFalse(default), axes keep their per-cell ranges. Triggers a rebuild of already-built HivePlot instances.Priority of params:
axis_kwargs> explicit dict values > auto-computed values.axis_kwargs – keyword arguments applied uniformly to every axis in every populated hive plot cell (e.g.
{"vmin": 0, "vmax": 1e9}to fix the display range across all axes). Applied post-construction viaupdate_axis(), so it overwrites any per-axis settings already present on the suppliedHivePlotinstances.node_kwargs – keyword arguments forwarded to the node rendering call for every hive plot cell. For the
matplotlibbackend these arescatter()kwargs; for thedatashaderbackend these areimshow()kwargs applied to the node rasterization. Can be overridden at plot time by passingnode_kwargsdirectly toplot().all_edge_kwargs – keyword arguments for all edges. Disregarded when using the
"datashader"backend.repeat_edge_kwargs – keyword arguments for repeat edges. Disregarded when using the
"datashader"backend.non_repeat_edge_kwargs – keyword arguments for non-repeat edges. Disregarded when using the
"datashader"backend.clockwise_edge_kwargs – keyword arguments for edges going clockwise. Disregarded when using the
"datashader"backend.counterclockwise_edge_kwargs – keyword arguments for edges going counterclockwise. Disregarded when using the
"datashader"backend.node_graph_metrics –
optional node graph-metric string name (or sequence of names) to compute and attach as columns to the underlying
hiveplotlib.NodeCollectionof every populated cell at construction time.Note
On the generic
HivePlotMatrixconstructor, metrics are computed and attached after sub-plot construction (every cell’sHivePlotinstance must already exist), so the resulting metric columns cannot drivepartition_variable/sorting_variablesinside each sub-plot. If you want to compute HPM partition or sorting variables on the fly, reach for one of thefrom_partition()/from_variable_sweep()/from_tags()classmethods instead. Those compute metrics before sub-plot construction.Each name must be a key in
hiveplotlib.graph_features.GRAPH_NODE_METRICS. Metrics are computed once per distinct underlyinghiveplotlib.NodeCollection/hiveplotlib.Edgespair across the matrix (deduplicated by identity), so global metrics likebetweenness_centralityproduce a consistent value across all cells that share the same source data. DefaultNoneskips computing any metrics.edge_graph_metrics –
optional edge graph-metric string name (or sequence of names) to compute and attach as columns to the underlying
hiveplotlib.Edgesof every populated cell at construction time.Note
Same timing caveat as
node_graph_metricsnote above: edge metrics are attached after sub-plot construction on this generic constructor and so cannot drive sub-plot partition / sorting variables. Reach for one of thefrom_*classmethods if you need metric-derived columns on the fly to feed into sub-plot construction.Each name must be a key in
hiveplotlib.graph_features.GRAPH_EDGE_METRICS. DefaultNoneskips computing any metrics.node_graph_metric_kwargs – per-metric
**kwargsto forward to each node-metric wrapper, keyed by metric name (e.g.{"betweenness_centrality": {"normalized": False}}).edge_graph_metric_kwargs – per-metric
**kwargsto forward to each edge-metric wrapper, keyed by metric name (e.g.{"edge_betweenness_centrality": {"normalized": False}}).node_graph_metric_rename – per-metric override mapping from metric name to the column name used on the resulting
hiveplotlib.NodeCollection. Useful for resolving collisions when a metric name already exists as a column.edge_graph_metric_rename – same as
node_graph_metric_renamebut for edge metrics.graph_metric_backend – name of a
networkxdispatchable backend (e.g."parallel", registered by thenx-parallelpackage) on which to compute any requested graph metrics. DefaultNonecomputes everything on default networkx. The value is stored on the resultingHivePlotMatrixand serves as the default for laterhiveplotlib.HivePlotMatrix.compute_graph_metrics()calls (see that method for the full precedence chain).degree,in_degree, andout_degreeare direct structural reads of the graph, so backend dispatch does not apply to them (the result is identical either way). Seehiveplotlib.graph_features.compute_graph_metrics()for backend-name validation and the fallback behavior for metrics a backend does not implement.graph_directed – this constructor fixes directedness to whatever you pass and never infers it from the requested metrics; use
from_partition()orfrom_variable_sweep()if you want directedness inferred from the metric set. It sets the directionality of the internalnetworkxgraph built when computing graph metrics; it does not affect how any hive plot cell is rendered. Directedness defaults toTrue, matching the(from, to)semantics ofhiveplotlib.Edges, so an undirected-only metric liketrianglesneeds an explicitgraph_directed=Falsehere. A requested set with both a directed-required and an undirected-required metric, or an explicitgraph_directedthat conflicts with a requested metric, raises aValueError.graph_multigraph – unlike
graph_directed, this is never inferred from the requested metrics. It controls whether each row in thehiveplotlib.Edgesclass counts as a distinct edge when metrics are computed (across all tags for multi-tag inputs); it does not affect how any hive plot cell is rendered. Defaults toFalse, collapsing repeated(from, to)rows into a single edge in the internal graph; setTrueto keep them distinct. PassingTruewith a metric that rejects multigraphs raises aValueError. See the note on parallel-edge collapse below.graph_source_attribute_name – edge-attribute name used internally to map each metric value computed on a repeated edge back to its specific source row when
graph_multigraph=True. Default"_hiveplotlib_source"works for nearly all use cases; override only if it collides with an existing edge column.warn_on_parallel_edge_collapse – whether to detect and warn about same-direction duplicate
(from, to)edges collapsing during metric computation. DefaultTrue. SettingFalseskips the detection entirely (a performance escape hatch for large graphs); it does not change whether edges collapse (duplicates are still merged last-write-wins). To preserve parallel edges instead, usegraph_multigraph=True.
Note
Controlling the internal graph type.
graph_directed,graph_multigraph, andgraph_source_attribute_nametogether pin the default type of the internalnetworkxgraph used to generate any requested graph metrics (directed vs. undirected, simple vs. multi, and how repeated edges map back to source rows). The one rule to keep in mind: directedness is inferred from the requested metrics only onfrom_partition()andfrom_variable_sweep()when you leavegraph_directedunset, while__init__andfrom_tags()keep whatever directedness you pass and never infer it. A graph built from agraphinput keeps its own type, andgraph_multigraphis never inferred on any path. The Computing Graph Metrics notebook walks through these cases, including the exact ways a graph-type mismatch stops computation.Note
Parallel-edge collapse. When
graph_multigraph=False(the default fornodes/edgesinput) and the edge data has same-direction duplicate(from, to)rows, those rows collapse last-write-wins and aUserWarningis emitted (skip it withwarn_on_parallel_edge_collapse=False). Reciprocal(a, b)/(b, a)rows that merge only because an undirected build treats the pair symmetrically do not warn (that merge is the definitional meaning of the undirected metric). Either collapse keeps a single row’s attributes, so a metric given an edgeweightreflects only one of two differing reciprocal weights.graph_multigraph=Trueretains both edges only for metrics that accept multigraphs; metrics that require a simple graph (e.g.onion_layers) reject the multigraph, so for those pre-aggregate the reciprocal weights into a single edge before building.
Properties#
- property HivePlotMatrix.shape: Tuple[int, int]#
Return the shape
(nrows, ncols)of the matrix.- Returns:
tuple of (number of rows, number of columns).
- property HivePlotMatrix.row_labels: List[Hashable] | None#
Return the row labels.
- Returns:
list of row labels, or
Noneif not set.
- property HivePlotMatrix.col_labels: List[Hashable] | None#
Return the column labels.
- Returns:
list of column labels, or
Noneif not set.
- property HivePlotMatrix.cell_labels: Dict[Tuple[int, int], Hashable] | None#
Return per-cell labels for wrapped layouts.
When
ncolswrapping is used, cell labels map(row, col)to the label for that cell. ReturnsNonefor non-wrapped layouts.- Returns:
dictionary mapping
(row, col)to label, orNone.
- property HivePlotMatrix.matrix_type: Literal['generic', 'from_partition', 'from_variable_sweep', 'from_tags']#
Return the matrix type.
- Returns:
one of
"generic","from_partition","from_variable_sweep", or"from_tags".
- property HivePlotMatrix.backend: Literal['matplotlib', 'datashader']#
Return the visualization backend currently set on this matrix.
Read-only; use
set_viz_backend()to change the backend.- Returns:
backend string (one of the values in
hiveplotlib.hiveplot_matrix.HPM_SUPPORTED_VIZ_BACKENDS).
Cell Access & Iteration#
- HivePlotMatrix.__getitem__(key: Tuple[int, int]) HivePlot | None#
Get a
HivePlotat position(row, col).- Parameters:
key –
(row, col)tuple.- Returns:
HivePlotinstance orNone.
Bulk Modification#
- HivePlotMatrix.set_viz_backend(backend: Literal['matplotlib', 'datashader']) None#
Set the visualization backend for the matrix and all populated cells.
- Parameters:
backend – which viz backend to use for plotting.
- Raises:
InvalidVizBackendError – if
backendis not a supported backend.- Returns:
None.
- HivePlotMatrix.update_all_edge_plotting_keyword_arguments(edge_kwarg_setting: Literal['all_edge_kwargs', 'repeat_edge_kwargs', 'non_repeat_edge_kwargs', 'clockwise_edge_kwargs', 'counterclockwise_edge_kwargs'] = 'all_edge_kwargs', reset_edge_kwarg_setting: bool = False, rebuild_edges: bool = False, **kwargs: object) None#
Update edge plotting keyword arguments for all populated cells.
- Parameters:
edge_kwarg_setting – which edge kwarg setting to modify.
reset_edge_kwarg_setting – whether to overwrite existing keyword arguments for the chosen
edge_kwarg_setting.rebuild_edges – whether to only update edge kwargs or to also redraw the edges. Default
Falseonly updates edge kwargs.kwargs – additional keyword arguments to provide to the specified edge kwarg setting.
- Returns:
None.
- HivePlotMatrix.compute_graph_metrics(*, node_graph_metrics: str | Sequence[str] | None = None, edge_graph_metrics: str | Sequence[str] | None = None, node_graph_metric_kwargs: dict[str, dict] | None = None, edge_graph_metric_kwargs: dict[str, dict] | None = None, node_graph_metric_rename: dict[str, str] | None = None, edge_graph_metric_rename: dict[str, str] | None = None, graph_metric_backend: str | None = None, graph_directed: bool | None = None, graph_multigraph: bool | None = None, graph_source_attribute_name: str | None = None, warn_on_parallel_edge_collapse: bool | None = None) None#
Compute graph metrics in place on every populated cell of this
HivePlotMatrix.For each populated cell, builds an internal
networkxgraph from its underlyinghiveplotlib.NodeCollection/hiveplotlib.Edges, runs the requested metrics, and replaces that cell’snodes/edgeswith augmented copies containing the resulting metric columns.Cells that share the same underlying
nodesandedgespair (by identity) have metrics computed exactly once and the result is propagated to every cell in the group, so global metrics likebetweenness_centralitystay consistent across cells sharing the same source data.Note
graph_directedandgraph_multigraphcontrol the internal graph used for metric computation only; they do not change how any hive plot cell is rendered. They do, however, affect which metrics are valid (e.g.in_degreerequiresgraph_directed=True).Note
Parallel-edge collapse. When
graph_multigraph=False(the default fornodes/edgesinput) and the edge data has same-direction duplicate(from, to)rows, those rows collapse last-write-wins and aUserWarningis emitted (skip it withwarn_on_parallel_edge_collapse=False). Reciprocal(a, b)/(b, a)rows that merge only because an undirected build treats the pair symmetrically do not warn (that merge is the definitional meaning of the undirected metric). Either collapse keeps a single row’s attributes, so a metric given an edgeweightreflects only one of two differing reciprocal weights.graph_multigraph=Trueretains both edges only for metrics that accept multigraphs; metrics that require a simple graph (e.g.onion_layers) reject the multigraph, so for those pre-aggregate the reciprocal weights into a single edge before building.- Parameters:
node_graph_metrics – string key (or sequence of keys) from
hiveplotlib.graph_features.GRAPH_NODE_METRICSto compute.edge_graph_metrics – string key (or sequence of keys) from
hiveplotlib.graph_features.GRAPH_EDGE_METRICSto compute.node_graph_metric_kwargs – per-metric
**kwargsto forward to each wrapper, keyed by node metric name (e.g.{"betweenness_centrality": {"normalized": False}}).edge_graph_metric_kwargs – same as
node_graph_metric_kwargsbut for edge metrics (e.g.{"edge_betweenness_centrality": {"normalized": False}}).node_graph_metric_rename – per-node metric column-name override (resolves collisions with existing node columns).
edge_graph_metric_rename – same as
node_graph_metric_renamebut for edge metrics.graph_metric_backend – name of a
networkxdispatchable backend on which to compute the requested metrics for this call. An explicit value applies to this call only and does not mutate the value stored at construction time; leftNone, the stored value is reused (to run just this one call on default networkx under a stored construction backend, passgraph_metric_backend="networkx"). Precedence when several levels are set: a per-metric"backend"entry innode_graph_metric_kwargs/edge_graph_metric_kwargsbeats this per-callgraph_metric_backend, which beats the value stored at construction time. See the parameter of the same name onHivePlotMatrixandhiveplotlib.graph_features.compute_graph_metrics()for backend-name validation and fallback behavior.graph_directed – directionality of the internal graph used for metric computation. An explicit value on this call applies to this call only, always wins, and does not mutate the stored setting; if it conflicts with a requested metric’s requirement, a
ValueErrorexplains the clash. LeftNone, behavior follows how theHivePlotMatrixwas constructed. If directedness was pinned at construction (via__init__orfrom_tags(), which take a concretegraph_directeddefault and always pin it; viafrom_partition()/from_variable_sweep()with an explicitgraph_directed; or any matrix built from agraph): the stored value is reused and not re-inferred, so a metric needing the opposite directedness raises the conflictValueError. If left unpinned (built viafrom_partition()/from_variable_sweep()fromnodes/edgeswithoutgraph_directed): directedness stays unpinned and is inferred from the requested set on every call when unambiguous (sonode_graph_metrics="triangles"builds an undirected graph), falling back toTruewhen the request does not decide it; a contradictory set (one metric needs a directed graph, another an undirected one) cannot be inferred and raises the conflictValueError.graph_multigraph – unlike
graph_directed, this is never inferred from the requested metrics. It controls whether each row in thehiveplotlib.Edgesclass counts as a distinct edge when metrics are computed (across all tags for multi-tag inputs). An explicit value on this call applies to this call only, wins, and does not mutate the stored setting; passingTruewith a metric that rejects multigraphs raises aValueError. LeftNone, uses the value stored at construction time (Falsewhen built fromnodes/edges,graph.is_multigraph()when built from agraph). See the note on parallel-edge collapse above.graph_source_attribute_name – edge-attribute name used internally to map each metric value computed on a repeated edge back to its specific source row when
graph_multigraph=True. Defaults to the value stored on thisHivePlotMatrixat construction time (__init__defaults to"_hiveplotlib_source", which works for nearly all use cases; override only if it collides with an existing edge column). Explicit overrides apply to this call only; they do not mutate the stored attribute.warn_on_parallel_edge_collapse – whether to detect and warn about same-direction duplicate
(from, to)edges collapsing during metric computation. LeftNone, uses the value stored at construction time (defaultTrue); an explicit value applies to this call only and does not mutate the stored setting. SettingFalseskips the detection entirely (a performance escape hatch for large graphs); it does not change whether edges collapse (duplicates are still merged last-write-wins). To preserve parallel edges instead, usegraph_multigraph=True.
- Returns:
None. Replaces each populated cell’snodes/edgesin place.- Raises:
ValueError – if the requested metrics have irreconcilable graph-type requirements for the single internal graph: a directedness standoff (one metric needs a directed graph, another an undirected one, caught across the node/edge boundary since they share one graph), or an explicit
graph_directed/graph_multigraphvalue that conflicts with a requested metric. Raised up front, before any metric runs. Resolve a standoff by running two calls, one pergraph_directedvalue.InvalidGraphMetricBackendError – if the effective
graph_metric_backend(or a per-metric"backend"entry) is not an installednetworkxdispatchable backend, targetsdegree/in_degree/out_degree, or is requested onnetworkx<3.2. Raised up front, before any metric runs; seehiveplotlib.graph_features.compute_graph_metrics().
Plotting#
- HivePlotMatrix.plot(**kwargs)#
Plot the hive plot matrix.
Creates a
matplotlibsubplot grid and renders each populated cell. Plotting behavior varies based on the matrix type:"from_partition": diagonal cells are zoomed to the repeat-axis quadrant with separate buffer and pixel-spread settings; labels are positioned relative to diagonal vs off-diagonal placement."from_variable_sweep"/"from_tags"/"generic": all cells rendered with identical settings (buffer, pixel spread, zoom).
Note
When the backend is set to
datashader, any provided node or edge plotting keyword arguments will be disregarded, as attributes like color and size are reserved for datashading. Globalvmaxvalues for node and edge density are auto-computed across all cells when not explicitly provided.- Parameters:
kwargs – keyword arguments forwarded to
hive_plot_matrix_viz().- Returns:
viz data structures. For the
matplotlibbackend,(fig, axes). For thedatashaderbackend,(fig, axes, im_nodes_dict, im_edges_dict). Seehive_plot_matrix_viz()for details.
Utilities#
- HivePlotMatrix.copy() HivePlotMatrix#
Return a deep copy of the
HivePlotMatrixinstance.- Returns:
copy of the
HivePlotMatrixinstance.
Constants#
- hiveplotlib.hiveplot_matrix.HPM_SUPPORTED_VIZ_BACKENDS#
The visualization backends supported by
HivePlotMatrix.A narrower set than
hiveplotlib.hiveplot.SUPPORTED_VIZ_BACKENDS:"matplotlib": the default; each cell renders into its ownAxeson a shared figure."datashader": each cell renders a rasterized aggregation viaimshow(), for matrices dense enough to benefit from server-side rasterization.
Set on a matrix via the
backendargument tohiveplotlib.HivePlotMatrix(or itsfrom_*constructors), or after construction withhiveplotlib.HivePlotMatrix.set_viz_backend().alias of
Literal[‘matplotlib’, ‘datashader’]
- hiveplotlib.hiveplot_matrix.HPM_MATRIX_TYPES#
The matrix types supported by
HivePlotMatrix."generic": constructed directly via__init__."from_partition": built viahiveplotlib.HivePlotMatrix.from_partition()."from_variable_sweep": built viahiveplotlib.HivePlotMatrix.from_variable_sweep()."from_tags": built viahiveplotlib.HivePlotMatrix.from_tags().
alias of
Literal[‘generic’, ‘from_partition’, ‘from_variable_sweep’, ‘from_tags’]