Hi,
I have started to use bokeh library, to visualize graph. It needs a edge list using NetworkX graph instance. But, everytime we plot the distribution of graphs is different.
I wanted to know about the algorithm which to used to generate the graph using
graph_render (an from_networkx instance) using Plot function from boke.models.
@amsi in general it’s not possible to say much without details/code. But IIRC the layout comes from NetworkX, in which case this is not really a Bokeh question.
Hi @amsi please edit your post to use code formatting. (either with the </> icon on the editing toolbar, or triple backtick ``` fences around the code blocks)
configures networkx to use the “spring layout”. That is part of networkx, not part of Bokeh. AFAIK it will generate a new random spring layout every time it is used. There are other layouts provided by networkx:
It’s possible some of those are more stable / will generate the same layout reliably. I am afraid I don’t know, you will have to try / investigate on your own. If not, or if you really want a spring layout, you would need to compute your layout once, I think you can just call nx,spring_layout yourself:
layout = nx.spring_layout(Gg)
And then you can pass this layout to from_networkx. But again, AFAIK nx.spring_layout will return a different layout every time it is called. So if you really want this to be the same in between different processs, you will have to find a way to persist the returned layout outside the process and re-load it. (Maybe a simple pickle woudl suffice, I don’t know) And of course: that can only possibly be expected work if the input graph is the same in every process.