"""
===========
Hiveplotlib
===========
`Hiveplotlib <https://hiveplotlib.readthedocs.io/>`_ is a network visualization
library for hive plots, a layout in which nodes are partitioned onto a small
number of radial axes and positioned along each axis by a sorting variable.
Since positions are determined by the data rather than a layout algorithm, hive
plots are reproducible and make structural properties of a graph directly legible.
Below, we visualize Zachary's Karate Club with both a conventional layout and a
hive plot.
"""
import matplotlib.pyplot as plt
import networkx as nx
from hiveplotlib import HivePlot
G = nx.karate_club_graph()
faction_color = [
"royalblue" if data["club"] == "Mr. Hi" else "darkorange"
for _, data in G.nodes(data=True)
]
fig, ax = plt.subplots(figsize=(8, 8))
nx.draw_circular(
G, with_labels=True, node_color=faction_color, font_color="white", ax=ax
)
plt.show()
hp = HivePlot(
graph=G,
partition_variable="club",
sorting_variables="degree",
node_graph_metrics="degree",
repeat_axes=True,
non_repeat_edge_kwargs={"color": "darkgray"},
)
hp.update_edges("Mr. Hi", "Mr. Hi", color="royalblue")
hp.update_edges("Officer", "Officer", color="darkorange")
hp.reset_edges(axis_id_1="Mr. Hi_repeat", axis_id_2="Officer")
fig, ax = hp.plot()
plt.show()