Can one get hierarchical graphs from networkx with python 3?

[scroll down a bit to see what kind of output the code produces] edit (7 Nov 2019) I’ve put a more refined version of this into a package I’ve been writing: https://epidemicsonnetworks.readthedocs.io/en/latest/_modules/EoN/auxiliary.html#hierarchy_pos. The main difference between the code here and the version there is that the code here gives all children of a given node … Read more

How can I specify an exact output size for my networkx graph?

You could try either smaller nodes/fonts or larger canvas. Here is a way to do both: import networkx as nx import matplotlib.pyplot as plt G = nx.cycle_graph(80) pos = nx.circular_layout(G) # default plt.figure(1) nx.draw(G,pos) # smaller nodes and fonts plt.figure(2) nx.draw(G,pos,node_size=60,font_size=8) # larger figure size plt.figure(3,figsize=(12,12)) nx.draw(G,pos) plt.show()

Add edge-weights to plot output in networkx

You’ll have to call nx.draw_networkx_edge_labels(), which will allow you to… draw networkX edge labels 🙂 EDIT: full modified source #!/usr/bin/python import networkx as nx import matplotlib.pyplot as plt G=nx.Graph() i=1 G.add_node(i,pos=(i,i)) G.add_node(2,pos=(2,2)) G.add_node(3,pos=(1,0)) G.add_edge(1,2,weight=0.5) G.add_edge(1,3,weight=9.8) pos=nx.get_node_attributes(G,’pos’) nx.draw(G,pos) labels = nx.get_edge_attributes(G,’weight’) nx.draw_networkx_edge_labels(G,pos,edge_labels=labels) plt.savefig(<wherever>)

Sharing Memory in Gunicorn?

It looks like the easiest way to do this is to tell gunicorn to preload your application using the preload_app option. This assumes that you can load the data structure as a module-level variable: from flask import Flask from your.application import CustomDataStructure CUSTOM_DATA_STRUCTURE = CustomDataStructure(‘/data/lives/here’) # @app.routes, etc. Alternatively, you could use a memory-mapped file … Read more

Improving Python NetworkX graph layout

In networkx, it’s worth checking out the graph drawing algorithms provided by graphviz via nx.graphviz_layout. I’ve had good success with neato but the other possible inputs are dot – “hierarchical” or layered drawings of directed graphs. This is the default tool to use if edges have directionality. neato – “spring model” layouts. This is the … Read more

networkx – change color/width according to edge attributes – inconsistent result

The order of the edges passed to the drawing functions are important. If you don’t specify (using the edges keyword) you’ll get the default order of G.edges(). It is safest to explicitly give the parameter like this: import networkx as nx G = nx.Graph() G.add_edge(1,2,color=”r”,weight=2) G.add_edge(2,3,color=”b”,weight=4) G.add_edge(3,4,color=”g”,weight=6) pos = nx.circular_layout(G) edges = G.edges() colors = … Read more