I’m writing a Jupyter notebook that takes a Netwokx graph with multiple data over the nodes and tries to draw it with Holoviews in order to best show the connections between nodes.
For this purpose, I’ve found easier to split the Networkx structure and populate hv.Nodes, hv.Graph and hv.Labels. I would love to be able to set the nodes shape to ovals instead of circles or rectangles since some labels are pretty long. Is there a way to do this? Looking at the documentation I could not find a oval shape, but just triangles, rectangles, crosses and circles.
Thanks for any help!
Looks like to do this we need to use the hooks option.
Adapting from the holoviews example:
import numpy as np
import holoviews as hv
from holoviews import opts
import networkx as nx
from bokeh.models import GraphRenderer, Ellipse
# Declare abstract edges
N = 8
node_indices = np.arange(N)
source = np.zeros(N)
target = node_indices
G = nx.DiGraph()
for t in target:
#for inspecting / tinkering with handler list; was only used for troubleshooting in later Jupyter cells
glyph_handlers = 
glyphs = [r for r in plot.handles.items() if 'glyph' in r]
glyph_handlers.extend(glyphs) # this was just used for troubleshooting if you want to be able to inspect them later to target different parts of the plot with your hook code
target_renderer = glyphs #this indexing was chosen after inspecting the handler order; probably need a more reliable way for plots with more layers
target_renderer.glyph = Ellipse(height=0.1, width=0.2,fill_color="fill_color")
simple_graph = hv.Graph.from_networkx(G,nx.layout.circular_layout).opts(hooks=[hook])