Skip to content

Commit 35f14d7

Browse files
committed
Initial implementation.
1 parent e5908dd commit 35f14d7

10 files changed

+3280
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
*.py[cod]
2+
__pycache__
23

34
# C extensions
45
*.so

README.md

+50-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,53 @@
11
nxpd
22
====
33

4-
Pydot drawing of NetworkX graphs with support for IPython notebooks.
4+
`nxpd` is a Python package for visualizing NetworkX graphs using `pydot`
5+
and `graphviz`. Support is also provided for inline displays within IPython
6+
notebooks.
7+
8+
Installation
9+
============
10+
Clone this repository:
11+
12+
git clone https://github.com/chebee7i/nxpd
13+
14+
Move into the directory and install the package.
15+
16+
python setup.py install
17+
18+
Usage
19+
=====
20+
21+
>>> import networkx as nx
22+
>>> from nxpd import draw
23+
>>> G = nx.cycle(4, create_using=nx.DiGraph())
24+
>>> draw(G)
25+
26+
This will display a PNG (by default) using your operating system's default
27+
PNG viewer. Alternatively, if you are in an IPython notebook, then you
28+
might like the image displayed inline. This is achieved by setting the `show`
29+
parameter of the `draw` function.
30+
31+
>>> draw(G, show='ipynb')
32+
33+
If you want all graphs to be drawn inline, then you can set a global parameter.
34+
35+
>>> from nxpd import nxpdParams
36+
>>> nxpdParams['show'] = 'ipynb'
37+
>>> draw(G)
38+
39+
Any graph/node/edge attribute that is supported by DOT is passed through to
40+
graphviz (via pydot). All others are skipped.
41+
42+
>>> G = nx.DiGraph()
43+
>>> G.graph['rankdir'] = 'LR'
44+
>>> G.graph['dpi'] = 120
45+
>>> G.add_cycle(range(4))
46+
>>> G.add_node(0, color='red', style='filled', fillcolor='pink')
47+
>>> G.add_node(1, shape='square')
48+
>>> G.add_node(3, style='filled', fillcolor='#00ffff')
49+
>>> G.add_edge(0, 1, color='red', style='dashed')
50+
>>> G.add_edge(3, 3, label='a')
51+
>>> draw(G)
52+
53+
![IPython Notebook Example](images/demo.png)

images/demo.png

72 KB
Loading

nxpd/__init__.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# -*- coding: utf-8 -*-
2+
3+
from __future__ import absolute_import
4+
5+
from .nx_pydot import draw_pydot as draw
6+
from .params import nxpdParams
7+
8+
__all__ = ['draw', 'nxpdParams']

0 commit comments

Comments
 (0)