vivainsights.network_p2p¶
Perform person-to-person network analysis and visualization.
- vivainsights.network_p2p.network_p2p(data, hrvar='Organization', return_type='plot', centrality=None, community=None, weight=None, comm_args=None, layout='mds', path='', style='igraph', bg_fill='#FFFFFF', font_col='grey20', legend_pos='best', palette='rainbow', node_alpha=0.7, edge_alpha=1, edge_col='#777777', node_sizes=[1, 20], node_scale=1, seed=1, legend_ncols=0, figsize=None)[source]¶
Return a network plot given a data frame containing a person-to-person query.
- Parameters:
data (pandas.DataFrame) – Data frame containing a person-to-person query.
hrvar (str) – Label for the HR attribute. Defaults to
"Organization".return_type (str) –
Type of output to return. Valid values:
"plot"(default): matplotlib Figure."plot-pdf": save network plot as PDF."sankey": sankey plot of communities × HR attribute."table": vertex summary table."data": vertex-level DataFrame."network": igraph object.
centrality (str, optional) – Centrality measure used to scale node sizes. Valid values:
"betweenness","closeness","degree","eigenvector","pagerank". WhenNone(default), nodes are uniform size.community (str, optional) – Community detection algorithm. Valid values:
"multilevel","leiden","edge_betweenness","fastgreedy","infomap","label_propagation","leading_eigenvector","optimal_modularity","spinglass","walk_trap". Defaults toNone.weight (str, optional) – Column to use as edge weights.
Nonecreates an unweighted graph.comm_args (dict, optional) – Keyword arguments passed to igraph’s clustering algorithm.
layout (str) – Node placement algorithm. Defaults to
"mds".path (str) – File path for PDF output. Defaults to an auto-generated name.
bg_fill (str) – Background fill colour. Defaults to
"#FFFFFF".font_col (str) – Font colour. Defaults to
"grey20".legend_pos (str) – Legend position (e.g.,
"best","upper left").palette (str) – Colour palette name. Defaults to
"rainbow".node_alpha (float) – Node transparency (0–1). Defaults to 0.7.
edge_alpha (float) – Edge transparency (0–1). Defaults to 1.
edge_col (str) – Edge colour. Defaults to
"#777777".node_sizes (list of int) – Two-element list
[min, max]for rescaling node sizes whencentralityis set. Defaults to[1, 20].node_scale (float) – Multiplier applied to node sizes. Defaults to 1.
seed (int) – Random seed for community detection reproducibility.
legend_ncols (int) –
0for horizontal legend,1for vertical.figsize (tuple, optional) – Figure size as
(width, height)in inches. Defaults to(8, 6).
- Returns:
Output depends on
return_type:"plot": matplotlib Figure."plot-pdf": saves PDF and returnsNone."sankey": sankey plot Figure."table": vertex summary DataFrame."data": vertex-level DataFrame."network": igraph object.
- Return type:
matplotlib.figure.Figure, pandas.DataFrame, or igraph.Graph
Examples
>>> import vivainsights as vi >>> sample_data = vi.p2p_data_sim() >>> vi.network_p2p(data=sample_data, return_type="plot") >>> >>> # Community detection with custom resolution >>> vi.network_p2p( ... data=sample_data, ... community="leiden", ... comm_args={"resolution": 0.01}, ... return_type="table", ... ) >>> >>> # Centrality-based node sizing >>> vi.network_p2p(data=sample_data, centrality="betweenness", return_type="table")