Last updated
Last updated
Networks help us visualize relationships between people and items. For example, a simple network can show you how people are related to each other. This is illustrated for you in the following diagram.
We can see Helen and Marius used to date but Helen is with Jonas, while Jonas and Marius are siblings. Marius and Ben are friends but Ben has no connection with Jonas.
Bokeh supports for creating network graph visualizations with configurable interactions between edges and nodes. One way is to connect two nodes with default straight lines, the other is to connect these networks by defining a shape for the path that we choose.
The key feature of the GraphRenderer
is that it maintains separate sub-GlyphRenderers for the graph nodes and the graph edges. This allows for customizing the nodes by modifying the GraphRenderer’s node_renderer
property.
The ColumnDataSource associated with the node sub-renderer must have a column named"index"
that contains the unique indices of the nodes.
The ColumnDataSource associated with the edge sub-renderer has two required columns: "start"
and "end"
. These columns contain the node indices for the start and end of the edges.
The easiest way to plot network graphs with Bokeh is to use thefrom_networkx
function. The example below shows a Bokeh plot ofnx.desargues_graph()
, setting some of the node and edge properties.
Adding Extra Data Columns
It’s possible to configure the selection or inspection behavior of graphs by setting the GraphRenderer’s selection_policy
and inspection_policy
attributes. These policy attributes accept a specialGraphHitTestPolicy
model instance.
For example, settingselection_policy=NodesAndLinkedEdges()
will cause a selected node to also select the associated edges. Similarly, settinginspection_policy=EdgesAndLinkedNodes()
will cause the start and end nodes of an edge to also be inspected upon hovering an edge with the HoverTool.