0

When plotting a network in Holoviews, how can I set the position of the nodes based on an attribute? I have a network with timestamps for each node, and would like to position the nodes based on the associated time.

sharx
  • 11
  • 3
  • Can you give an example graph to begin with ? – Gambit1614 Jun 26 '18 at 21:46
  • I figured it out, but am still looking for ways to find the optimal y position, given the x positions (see https://stackoverflow.com/questions/51065995/holoviews-graph-visualization-get-optimal-y-position-given-x-position). If you have any ideas it'd be much appreciated! – sharx Jun 27 '18 at 15:01

1 Answers1

0

I figured out how to set the x position based on an attribute, but I would still like holoviews to find the optimal y position (see Holoviews graph visualization: get optimal y position, given x position).

The code below sets the x position based on a node attribute:

import holoviews as hv
import numpy as np
import pandas as pd
import networkx as nx

N = 5
num_edges = 2
list1 = np.arange(N).tolist()*num_edges
list2 = np.array(list1)
np.random.shuffle(list2)
edgelist = pd.DataFrame({'vertex1': list1, 'vertex2': list2, 'weight': np.random.uniform(0, 1, len(list1))})
edgelist = edgelist[edgelist.vertex1 != edgelist.vertex2]
edgelist = edgelist.drop_duplicates()
times = pd.DataFrame({'vertex': np.arange(N), 'time': np.random.normal(0, 10, N)})

x = times.time
y = np.random.uniform(0, 1, N)
padding = dict(x=(np.min(x) - 1, np.max(x) + 1), y=(-1.2, 1.2))
node_indices = np.arange(N)


pos_graph = hv.Graph(((edgelist.vertex1, edgelist.vertex2), (x, y, node_indices))).redim.range(**padding)
pos_graph
sharx
  • 11
  • 3