|
1 | 1 | nxpd
|
2 | 2 | ====
|
3 | 3 |
|
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 | + |
0 commit comments