Git Product home page Git Product logo

nxpd's Introduction

nxpd

nxpd is a Python package for visualizing NetworkX graphs using pydot and graphviz. Support is also provided for inline displays within IPython notebooks.

Installation

Installation is easy:

pip install nxpd

Alternatively, you can use git:

git clone https://github.com/chebee7i/nxpd

Then, move into the nxpd directory and install the old fashioned way:

python setup.py install

Usage

Basic usage is as follows:

import networkx as nx
from nxpd import draw
G = nx.cycle_graph(4, create_using=nx.DiGraph())
draw(G)

This will display a PNG (by default) using your operating system's default PNG viewer. Alternatively, if you are in an IPython notebook, then you might like the image displayed inline. This is achieved by setting the show parameter of the draw function.

draw(G, show='ipynb')

If you want all graphs to be drawn inline, then you can set a global parameter.

from nxpd import nxpdParams
nxpdParams['show'] = 'ipynb'
draw(G)

Any graph/node/edge attribute that is supported by DOT is passed through to graphviz (via pydot). All others are skipped.

G = nx.DiGraph()
G.graph['rankdir'] = 'LR'
G.graph['dpi'] = 120
G.add_cycle(range(4))
G.add_node(0, color='red', style='filled', fillcolor='pink')
G.add_node(1, shape='square')
G.add_node(3, style='filled', fillcolor='#00ffff')
G.add_edge(0, 1, color='red', style='dashed')
G.add_edge(3, 3, label='a')
draw(G)

IPython Notebook Example

nxpd's People

Contributors

chebee7i avatar hagberg avatar rainwoodman avatar wuhaochen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nxpd's Issues

Saving images made with the draw method

How would one save a graph created with the draw method? I presently use the command in ipython with the show='ipython' argument (works great), but it isn't clear to me how to save the image as a .png or .pdf.

make nxpd available on PyPI

Hi chebee7i,

thank you for writing this package.
Could you please make it available on PyPI as well?

Best regards,
Arne

Bump up version

We want to use nxpd with Python 3.4. However, this commit (c962ee5) is not included in ver.0.1.2.

Would you please dump up version in PyPI.

'DiGraph' object has no attribute 'number_of_selfloops'

I am trying to run the below code (in Jupyter-notebook) using networkx==2.4 and nxpd==0.2.0

import networkx as nx
import nxpd
from nxpd import draw
from nxpd import nxpdParams
nxpdParams["show"] = "ipynb"

G = nx.DiGraph()
G.add_node("Hello World")
draw(G)

However I get the error

'DiGraph' object has no attribute 'number_of_selfloops'

I am aware this function has been depreciated in networkx==2.4 but are there any plans for a fix to nxpd or any quick fixes I could use in the meantime?

using latex node or edge labels

Hi, useful project, thanks!
Is it possible to use latex for node or edge labels?

G = nx.MultiDiGraph(with_labels=False,rankdir='LR')
G.graph['dpi'] = 120
G.add_node(1,label=r"$\sigma_1$",shape = 'circle')
G.add_node(2,label=r"$\sigma_2$",shape = 'circle')
G.add_edge(1,1,headport='nw',tailport='sw',label='sp')
G.add_edge(2,2,headport='se',tailport='ne')
G.add_edge(1,2,label='1-sp')

im = draw(G, layout='circo')
im

which gives this output:

index

thanks for any help!

Temporary files.

Sorry, one more as I scan through the code. I am not sure if this one make much sense.

Apparently all of the graphviz executables nxpd uses can read from stdin. We can likely do away with the temp files with .communicate . I wonder why original pydot chose to write to a temp file though.

However, in a longer term maybe we want to avoid spawn/fork/exec all together; they won't reliably work, for example, in a MPI program. -- I don't quite see why one would be visualizing graphs in a MPI program though.

Allowing user provided `filter_attrs`?

One more comment.

A user provided filter_attrs function will allow the user to generate the pydot attributes as we iterate over the graph, without requiring these attributes be saved into the data dict of node nor edges.

This essentially splits the graph data model (G) and the view (filter_attrs). It also reduces chances of having conflicts on the data dict.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.