Bokeh Networkx Graph rendering: failed to validate StaticLayoutProvider

Trying to create a networkX graph to render on bokeh.
I have also tried using the kamada_kawai_layout

network_graph = from_networkx(G, nx.spring_layout, scale=10, center=(0, 0))
network_graph = from_networkx(G, nx.spring_layout, scale=10, center=(0, 0))
  File "/opt/homebrew/lib/python3.11/site-packages/bokeh/plotting/", line 123, in from_networkx
    graph_renderer.layout_provider = StaticLayoutProvider(graph_layout=graph_layout)
  File "/opt/homebrew/lib/python3.11/site-packages/bokeh/models/", line 83, in __init__
    super().__init__(*args, **kwargs)
  File "/opt/homebrew/lib/python3.11/site-packages/bokeh/models/", line 66, in __init__
    super().__init__(*args, **kwargs)
  File "/opt/homebrew/lib/python3.11/site-packages/bokeh/model/", line 110, in __init__
  File "/opt/homebrew/lib/python3.11/site-packages/bokeh/core/", line 295, in __init__
    setattr(self, name, value)
  File "/opt/homebrew/lib/python3.11/site-packages/bokeh/core/", line 327, in __setattr__
    return super().__setattr__(name, value)
  File "/opt/homebrew/lib/python3.11/site-packages/bokeh/core/property/", line 332, in __set__
    value =,, value)
  File "/opt/homebrew/lib/python3.11/site-packages/bokeh/core/property/", line 364, in prepare_value
    raise ValueError(f"failed to validate {obj_repr}.{name}: {error}")
ValueError: failed to validate StaticLayoutProvider(id='p1052', ...).graph_layout: expected an element of Dict(Int, Seq(Any)), got {'6': array([-5.70519103,  0.71927349]), '21': array([-1.62685515,  0.65761607]),

A minimal example is always helpful to be able to investigate the problem.

Also, your error message doesn’t seem to be complete.

I don’t use the networkx module. Though, having a look at the last line of the error message, I observe the following:

expected an element of Dict(Int, Seq(Any))
So the keys of the dictionary should actually be integers.

got {'6': array([-5.70519103, 0.71927349]),
But the keys in your input (here '6') are strings, recognizable by the two apostrophes.

Do you still observe the problem if you first convert the foreseen keys to integers, for instance with the int() function?

@Icoti is correct: at present, the node indices may only be integers.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.