Do you have a gigantic graph, maybe one with 500k nodes and edges? It probably doesn't display well at all when you draw it in matplotlib. Never fear: this package will let you display the graph in ElGrapho, a high-performance and interactive graph viewer built using WebGL.
Install python3 and then pip install "git+https://github.com/dpinney/pygrapho"
Here's a simple example, rendering to a file:
import pygrapho
graph = {
"nodes":[{"x":0, "y":0.6}, {"x":-0.4, "y":0}, {"x":0.4, "y":0}, {"x":-0.6, "y":-0.6}, {"x":-0.2, "y":-0.6}, {"x":0.2, "y":-0.6}, {"x":0.6, "y":-0.6}],
"edges":[{"from":0, "to":1}, {"from":0, "to":2}, {"from":1, "to":3}, {"from":1, "to":4}, {"from":2, "to":5}, {"from":2, "to":6}]
}
options = {
'darkMode': True,
'glowBlend': 0.2,
'edgeSize': 1,
'fillContainer': True
}
pygrapho.render_file(graph, options, 'None', open_file=True)
The result is rendered to a temporary file and opened:
Pygrapho also works inside jupyter:
And it works on huge graphs (this one has 10k vertices):
import pygrapho
pygrapho.render_file(pygrapho._chord_model_example(), pygrapho._test_options, 'Chord', open_file=True)
If you already have a networkx graph, you can convert it automatically:
import networkx as nx
import pygrapho
G = nx.generators.trees.random_tree(100)
model = pygrapho.convert_networkx(G)
pygrapho.render_file(model, pygrapho._test_options, 'ForceDirected', open_file=True)
If you'd like more information on the various options available, please see the ElGrapho documentation, v2.4.0. There are lots of different layout and styling types:
ElGrapho, of course, without which none of this would be possible.
Some hints from jacobstallone and the Jupyter team on how to get javascript to work well inside notebooks.
- OOO Publish python module to pypi. E.g. Install python3 and then run
pip install pygrapho
. - OOO More tests, CI/CD.
- OOO Support for networkx position translation.
- OOO Validate options schema and the model. https://pypi.org/project/schema/
- OOO Remove fstrings for py2 compatibility.
- OOO Leaflet with blank canvas: https://stackoverflow.com/questions/28094649/add-option-for-blank-tilelayer-in-leaflet-layergroup
- OOO Give it a shot in maptiler.