Skip to content

Visualize Extremely Large Graphs in Python and ElGrapho

License

Notifications You must be signed in to change notification settings

dpinney/pygrapho

Repository files navigation

pygrapho Overview

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.

Installation

Install python3 and then pip install "git+https://github.com/dpinney/pygrapho"

Usage

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:

manual graph

Pygrapho also works inside jupyter:

jupyter example

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)

10k node chord graph

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)

random tree force directed

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:

grapho example renderings

Acknowledgments

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.

Todos

About

Visualize Extremely Large Graphs in Python and ElGrapho

Resources

License

Stars

Watchers

Forks

Packages

No packages published