In [1]:
from hiveplotter import HivePlot
import networkx as nx
import random as rand
from matplotlib import pyplot as plt
%matplotlib inline
import pylab
pylab.rcParams['figure.figsize'] = (20.0, 15.0)
Set up a graph with 250 nodes in 3 classes, and 500 edges between random pairs of nodes, in 3 random classes and with a random weight
In [2]:
edge_types = ['a-edge', 'b-edge', 'c-edge']
node_classes = ['x-node', 'y-node', 'z-node']
G = nx.Graph()
for node_ID in ("node{}".format(n) for n in range(250)):
G.add_node(node_ID, type=rand.choice(node_classes), other_attr=rand.random())
for _ in range(500):
G.add_edge(*rand.sample(G.nodes(), 2), type=rand.choice(edge_types), weight=rand.triangular(0, 1, 0))
The hive plot for graph G with default arguments. Note:
In [3]:
hive_plot = HivePlot(G, node_class_attribute='type', node_class_values=None)
hive_plot.draw()
plt.imshow(hive_plot.as_bitmap(resolution=150))
Out[3]:
Colour changes, using the same graph. Note:
In [4]:
hive_plot2 = HivePlot(G,
edge_colour_attribute='random',
edge_colour_gradient='Hue',
default_node_colour='Orange',
order_nodes_by='other_attr',
background_colour='Brown',
axis_colour='White',
label_colour='Yellow'
)
hive_plot2.draw()
plt.imshow(hive_plot2.as_bitmap(resolution=150))
Out[4]:
Some changes to the representation of nodes and edges, using the same graph. Note:
In [5]:
hive_plot3 = HivePlot(G,
node_class_values=['z-node', 'y-node', 'x-node'],
edge_colour_attribute='type',
edge_colour_gradient='Rainbow',
edge_category_legend=True,
node_superimpose_representation='colour'
)
hive_plot3.draw()
plt.imshow(hive_plot3.as_bitmap(resolution=150))
Out[5]:
Demonstrating the splitting of axes to allow visualisation of intra-class edges.
In [6]:
hive_plot4 = HivePlot(G,
split_axes=['y-node', 'x-node']
)
hive_plot4.draw()
plt.imshow(hive_plot4.as_bitmap(resolution=150))
Out[6]:
In [ ]: