Lesmis example¶
Download this notebook from GitHub (right-click to download).
In [1]:
import numpy as np
import holoviews as hv
from holoviews import opts
hv.extension('bokeh')
Declare data¶
In [2]:
from bokeh.sampledata.les_mis import data
nodes = data['nodes']
names = [node['name'] for node in sorted(data['nodes'], key=lambda x: x['group'])]
N = len(nodes)
counts = np.zeros((N, N))
for link in data['links']:
counts[link['source'], link['target']] = link['value']
counts[link['target'], link['source']] = link['value']
xname, yname, color, alpha = [], [], [], []
for i, node1 in enumerate(nodes):
for j, node2 in enumerate(nodes):
xname.append(node1['name'])
yname.append(node2['name'])
alpha.append(counts[i,j])
if node1['group'] == node2['group']:
color.append(node1['group'])
else:
color.append('lightgrey')
ds = hv.Dataset((xname, yname, color, alpha), ['x', 'y', 'Cluster', 'Occurences'])
overlaid = ds.to(hv.HeatMap, ['x', 'y'], ['Occurences']).overlay()
Plot¶
In [3]:
cmaps = ['Greys', 'Reds', 'Greys', 'Greens', 'Blues',
'Purples', 'Oranges', 'Greys', 'Greys', 'PuRd', 'Reds', 'Greys']
combined = hv.Overlay([o.opts(cmap=cm).sort() for o, cm in zip(overlaid, cmaps)], label='LesMis Occurences')
styled = combined.opts(
opts.HeatMap(logz=True, clim=(0.1, None), clipping_colors={'NaN':(1,1,1,0.)}, xaxis='top', xrotation=90,
fontsize={'ticks': '7pt', 'title': '18pt'}, invert_xaxis=True, tools=['hover'],
labelled=[], axiswise=True),
opts.Overlay(height=800, width=800)
)
styled
Out[3]:
In [4]:
hv.Layout([el.opts(width=300, height=300) for el in styled if len(el)>10][:-1],
label='LesMis Large Clusters').cols(3)
Out[4]:
Download this notebook from GitHub (right-click to download).