Network/graph plotting in Bokeh (from networkx)

This is a question from 5 years ago that I wanted to re-ask.

There are a bunch of graph/network visualization packages out there but often require local binary installation and are kind of difficult for many Jupyter notebook users to get going. We’ve search for a while for something usable in notebooks but haven’t come across anything (and already use Bokeh in our msticpy pacakge for several other visualizations).

Most of what you would need to render/visualize/interact with a network is already in Bokeh and the rendering perf would allow it work pretty well with even large graphs.

The things that would be top of my priority list are:

  • a decently-sized gallery example of creating a graph with a few hundred nodes that has things like tooltips populated from nx attributes
  • dynamic layout and ability to control some parameters interactively (examples I’ve seen use a static layout from an NX layout but not having the glyph layout recalculate dynamically). Ability to add layout algos would be a bonus.

I’d be happy to help with the gallery example but my knowledge of JS and the Bokeh programming model is close to zero.

The question from five years ago predates all of Bokeh’s network graph support, including e.g. the from_networkx method that does currently exist. So it’s not really clear what the focus is about. I guess I’d turn around things and point to this chapter of the docs:

https://docs.bokeh.org/en/latest/docs/user_guide/graph.html

and instead ask: what is missing for you, relative to that?

Thx Bryan,
Yes, good correction. I had looked at and implemented the examples in that chapter.
(and, apologies - I’d forgotten that you can populate tooltips from nx attribs). I think the main thing is the dynamics of the graph - the ability to drag a node and have the layout recalculate and re-render.

I realize that this isn’t an apples-to-apples comparison - this is something you find in dedicated network/graphing tools and not in other plotting/viz frameworks that I know about.

OK, great, I was not sure if it was the interactivity that was the focus or now. @Philipp_Rudiger do the edit tools work with graph nodes? I feel like I saw something about this recently in the past.

Edit: in case you want to try immediately, the PointDrawTool is documented here:

https://docs.bokeh.org/en/latest/docs/user_guide/tools.html#pointdrawtool

I don’t see why it wouldn’t work with graph renderer nodes, but at present I would expect only a basic default straight line edges to work. If you provide explicit path coordinates, those obviously would not update and would be out of date as soon as a node was moved. I think we’d like to add some sort of bezier path option sometime in the near-ish future. Also in case it needs to be stated using the pint draw tool only updates the one node that a user would drag, nothing else would be “recomputed”. It would require a custom extension to do that.

1 Like

No, that doesn’t seem to work for some reason. I’ve been meaning to look at that for a long time, just haven’t gotten around to it.

It would definitely be nice to have dynamic layout recalculation. There are graph layout calculation JS libraries out there (https://github.com/dhotson/springy/ - although this is a bit old). How complex would it be to plumb something like this in to a custom extension?