import numpy as np import pandas as pd import holoviews as hv import networkx as nx hv.extension('bokeh') %opts Graph [width=400 height=400] # Declare abstract edges N = 8 node_indices = np.arange(N, dtype=np.int32) source = np.zeros(N, dtype=np.int32) target = node_indices padding = dict(x=(-1.2, 1.2), y=(-1.2, 1.2)) simple_graph = hv.Graph(((source, target),)).redim.range(**padding) simple_graph simple_graph.nodes + simple_graph.edgepaths def bezier(start, end, control, steps=np.linspace(0, 1, 100)): return (1-steps)**2*start + 2*(1-steps)*steps*control+steps**2*end x, y = simple_graph.nodes.array([0, 1]).T paths = [] for node_index in node_indices: ex, ey = x[node_index], y[node_index] paths.append(np.column_stack([bezier(x[0], ex, 0), bezier(y[0], ey, 0)])) bezier_graph = hv.Graph(((source, target), (x, y, node_indices), paths)).redim.range(**padding) bezier_graph bezier_graph.options(inspection_policy='edges') %%opts Graph [tools=['hover', 'box_select']] (edge_hover_line_color='green' node_hover_fill_color='red') bezier_graph.options(inspection_policy='nodes') %%opts Graph [color_index='Type' edge_color_index='Weight'] (cmap='Set1' edge_cmap='viridis') node_labels = ['Output']+['Input']*(N-1) np.random.seed(7) edge_labels = np.random.rand(8) nodes = hv.Nodes((x, y, node_indices, node_labels), vdims='Type') graph = hv.Graph(((source, target, edge_labels), nodes, paths), vdims='Weight').redim.range(**padding) graph + graph.options(inspection_policy='edges') %%opts Graph [color_index='Label'] (cmap='Set1') node_info = hv.Dataset(node_labels, vdims='Label') hv.Graph(((source, target), node_info)).redim.range(**padding) %%opts Graph [tools=['hover']] G = nx.karate_club_graph() hv.Graph.from_networkx(G, nx.layout.circular_layout).redim.range(**padding) %%opts Graph G = nx.karate_club_graph() def get_graph(iteration): np.random.seed(10) return hv.Graph.from_networkx(G, nx.spring_layout, iterations=iteration) hv.HoloMap({i: get_graph(i) for i in range(5, 30, 5)}, kdims='Iterations').redim.range(x=(-1.2, 1.2), y=(-1.2, 1.2)) %opts Nodes Graph [width=800 height=800 xaxis=None yaxis=None] %%opts Graph [color_index='circle'] %%opts Graph (node_size=10 edge_line_width=1) colors = ['#000000']+hv.Cycle('Category20').values edges_df = pd.read_csv('../assets/fb_edges.csv') fb_nodes = hv.Nodes(pd.read_csv('../assets/fb_nodes.csv')).sort() fb_graph = hv.Graph((edges_df, fb_nodes), label='Facebook Circles') fb_graph = fb_graph.redim.range(x=(-0.05, 1.05), y=(-0.05, 1.05)).options(cmap=colors) fb_graph from holoviews.operation.datashader import datashade, bundle_graph bundled = bundle_graph(fb_graph) bundled %%opts Nodes [color_index='circle'] (size=10 cmap=colors) Overlay [show_legend=False] datashade(bundled, normalization='linear', width=800, height=800) * bundled.nodes %%opts Graph (node_fill_color='white') datashade(bundle_graph(fb_graph), normalization='linear', width=800, height=800) *\ bundled.select(circle='circle15') bundled.select(circle='circle15', selection_mode='nodes')