☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Auto ranges in graph from networkx

Community Support
Katterrina
Katterrina

Hi!

In user guide (1) is written that “By default, plots generated with the bokeh.plotting interface come configured with DataRange1d objects that try to automatically set the plot bounds to encompass all the available data.” That it exactly what I want, but it does not work for figure with from_networkx graph renderer.

Here is simplified example of the problem:

import networkx as nx
from bokeh.plotting import figure, curdoc, from_networkx
from bokeh.models import Range1d, DataRange1d

# create networkx graph
g = nx.Graph()
g.add_nodes_from([(4,{"sheet":"A","coor":(2,1)}),
				  (5,{"sheet":"A","coor":(2,2)}),
				  (6,{"sheet":"A","coor":(3,1)}),
				  (7,{"sheet":"A","coor":(3,2)})])

g.add_edges_from([(4,5,{'weight':1, 'delay':1}),
				  (5,6,{'weight':1, 'delay':1}),
				  (4,6,{'weight':1, 'delay':1}),
				  (6,7,{'weight':1, 'delay':1})])

layout = {n:g.nodes[n]["coor"] for n in g.nodes()}

# create graph renderer from networkx graph
graph_renderer = from_networkx(g,layout)

plot = figure(x_range=Range1d(), y_range=Range1d()) # graph is plotted, but outside of visible area, it is necessary to move it
# plot = figure() there are no ranges and nothing plotted in the result
# plot = figure(x_range=DataRange1d(), y_range=DataRange1d()) same as plot = figure()
# plot = figure(x_range=(1,4),y_range=(0,3)) works, but I do not want to set ranges on my own
plot.renderers.append(graph_renderer)

curdoc().add_root(plot)

In user guide in section about network graphs (2) are all ranges explicitly set. Is there some way how to set them according the graph renderer?

Thank you,
Katerina

⌁   Link to post

End of archived discussion · Replies are disabled