hiveplotter usage


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:

  • The edge thickness and colour, proportional to the edge's weight.
  • Nodes arrayed up the axes in order of their degree (controllable with the order_nodes_by kwarg).
  • The node size, representing the number of nodes at that locus on the axis.

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))


WARNING:pyx:Ignoring line 8411 in mapping file 'psfonts.map': Unknown token '<MinLibBol'
WARNING:pyx:Ignoring line 8412 in mapping file 'psfonts.map': Unknown token '<MinLibBol'
WARNING:pyx:Ignoring line 8413 in mapping file 'psfonts.map': Unknown token '<MinLibBol'
WARNING:pyx:Ignoring line 8414 in mapping file 'psfonts.map': Unknown token '<MinLibBolIta'
WARNING:pyx:Ignoring line 8415 in mapping file 'psfonts.map': Unknown token '<MinLibBolIta'
WARNING:pyx:Ignoring line 8416 in mapping file 'psfonts.map': Unknown token '<MinLibBolIta'
WARNING:pyx:Ignoring line 8417 in mapping file 'psfonts.map': Unknown token '<MinLibIta'
WARNING:pyx:Ignoring line 8418 in mapping file 'psfonts.map': Unknown token '<MinLibIta'
WARNING:pyx:Ignoring line 8419 in mapping file 'psfonts.map': Unknown token '<MinLibIta'
WARNING:pyx:Ignoring line 8420 in mapping file 'psfonts.map': Unknown token '<MinLibReg'
WARNING:pyx:Ignoring line 8421 in mapping file 'psfonts.map': Unknown token '<MinLibReg'
WARNING:pyx:Ignoring line 8422 in mapping file 'psfonts.map': Unknown token '<MinLibReg'
Out[3]:
<matplotlib.image.AxesImage at 0x7fce10f21e80>

Colour changes, using the same graph. Note:

  • The change to node colour.
  • The change to node locations, due to ordering them by other_attr
  • The random edge colouration and selection of gradient.

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))


WARNING:pyx:Ignoring line 8411 in mapping file 'psfonts.map': Unknown token '<MinLibBol'
WARNING:pyx:Ignoring line 8412 in mapping file 'psfonts.map': Unknown token '<MinLibBol'
WARNING:pyx:Ignoring line 8413 in mapping file 'psfonts.map': Unknown token '<MinLibBol'
WARNING:pyx:Ignoring line 8414 in mapping file 'psfonts.map': Unknown token '<MinLibBolIta'
WARNING:pyx:Ignoring line 8415 in mapping file 'psfonts.map': Unknown token '<MinLibBolIta'
WARNING:pyx:Ignoring line 8416 in mapping file 'psfonts.map': Unknown token '<MinLibBolIta'
WARNING:pyx:Ignoring line 8417 in mapping file 'psfonts.map': Unknown token '<MinLibIta'
WARNING:pyx:Ignoring line 8418 in mapping file 'psfonts.map': Unknown token '<MinLibIta'
WARNING:pyx:Ignoring line 8419 in mapping file 'psfonts.map': Unknown token '<MinLibIta'
WARNING:pyx:Ignoring line 8420 in mapping file 'psfonts.map': Unknown token '<MinLibReg'
WARNING:pyx:Ignoring line 8421 in mapping file 'psfonts.map': Unknown token '<MinLibReg'
WARNING:pyx:Ignoring line 8422 in mapping file 'psfonts.map': Unknown token '<MinLibReg'
Out[4]:
<matplotlib.image.AxesImage at 0x7fce146f3898>

Some changes to the representation of nodes and edges, using the same graph. Note:

  • The explicit order of the 3 node classes.
  • The edges coloured by their type, and the legend.
  • The superimposed nodes represented by colour rather than size.

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))


WARNING:pyx:Ignoring line 8411 in mapping file 'psfonts.map': Unknown token '<MinLibBol'
WARNING:pyx:Ignoring line 8412 in mapping file 'psfonts.map': Unknown token '<MinLibBol'
WARNING:pyx:Ignoring line 8413 in mapping file 'psfonts.map': Unknown token '<MinLibBol'
WARNING:pyx:Ignoring line 8414 in mapping file 'psfonts.map': Unknown token '<MinLibBolIta'
WARNING:pyx:Ignoring line 8415 in mapping file 'psfonts.map': Unknown token '<MinLibBolIta'
WARNING:pyx:Ignoring line 8416 in mapping file 'psfonts.map': Unknown token '<MinLibBolIta'
WARNING:pyx:Ignoring line 8417 in mapping file 'psfonts.map': Unknown token '<MinLibIta'
WARNING:pyx:Ignoring line 8418 in mapping file 'psfonts.map': Unknown token '<MinLibIta'
WARNING:pyx:Ignoring line 8419 in mapping file 'psfonts.map': Unknown token '<MinLibIta'
WARNING:pyx:Ignoring line 8420 in mapping file 'psfonts.map': Unknown token '<MinLibReg'
WARNING:pyx:Ignoring line 8421 in mapping file 'psfonts.map': Unknown token '<MinLibReg'
WARNING:pyx:Ignoring line 8422 in mapping file 'psfonts.map': Unknown token '<MinLibReg'
Out[5]:
<matplotlib.image.AxesImage at 0x7fce146cd240>

Demonstrating the splitting of axes to allow visualisation of intra-class edges.

  • The angle between split axes can be controlled with the split_angle kwarg.

In [6]:
hive_plot4 = HivePlot(G,
                      split_axes=['y-node', 'x-node']
    )
hive_plot4.draw()
plt.imshow(hive_plot4.as_bitmap(resolution=150))


WARNING:pyx:Ignoring line 8411 in mapping file 'psfonts.map': Unknown token '<MinLibBol'
WARNING:pyx:Ignoring line 8412 in mapping file 'psfonts.map': Unknown token '<MinLibBol'
WARNING:pyx:Ignoring line 8413 in mapping file 'psfonts.map': Unknown token '<MinLibBol'
WARNING:pyx:Ignoring line 8414 in mapping file 'psfonts.map': Unknown token '<MinLibBolIta'
WARNING:pyx:Ignoring line 8415 in mapping file 'psfonts.map': Unknown token '<MinLibBolIta'
WARNING:pyx:Ignoring line 8416 in mapping file 'psfonts.map': Unknown token '<MinLibBolIta'
WARNING:pyx:Ignoring line 8417 in mapping file 'psfonts.map': Unknown token '<MinLibIta'
WARNING:pyx:Ignoring line 8418 in mapping file 'psfonts.map': Unknown token '<MinLibIta'
WARNING:pyx:Ignoring line 8419 in mapping file 'psfonts.map': Unknown token '<MinLibIta'
WARNING:pyx:Ignoring line 8420 in mapping file 'psfonts.map': Unknown token '<MinLibReg'
WARNING:pyx:Ignoring line 8421 in mapping file 'psfonts.map': Unknown token '<MinLibReg'
WARNING:pyx:Ignoring line 8422 in mapping file 'psfonts.map': Unknown token '<MinLibReg'
Out[6]:
<matplotlib.image.AxesImage at 0x7fce10e21eb8>

In [ ]: