import numpy as np import holoviews as hv from holoviews import opts hv.extension('bokeh') opts.defaults(opts.Graph(width=400, height=400)) # Declare abstract edges N = 8 node_indices = np.arange(N) source = np.zeros(N) target = node_indices simple_graph = hv.Graph(((source, target),)) simple_graph simple_graph.opts(directed=True, arrowhead_length=0.05) simple_graph.nodes + simple_graph.edgepaths # Node info np.random.seed(7) x, y = simple_graph.nodes.array([0, 1]).T node_labels = ['Output']+['Input']*(N-1) edge_weights = np.random.rand(8) # Compute edge paths def bezier(start, end, control, steps=np.linspace(0, 1, 100)): return (1-steps)**2*start + 2*(1-steps)*steps*control+steps**2*end 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)])) # Declare Graph nodes = hv.Nodes((x, y, node_indices, node_labels), vdims='Type') graph = hv.Graph(((source, target, edge_weights), nodes, paths), vdims='Weight') graph.opts(node_color='Type', edge_color='Weight', cmap=['blue', 'red'], edge_cmap='viridis')