Auto ranges in graph from networkx


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_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


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,

Not at present. Currently only plain glyph renderers (which are all that existed when the quoted docs sentence was written) participate in auto-ranging. Feel free to open a Github issue to propose this feature.

Thank you for your answer, here is the issue:

1 Like