tags:

views:

122

answers:

3

I have data that I want to represent visually. The actual data is a tree made up of nodes. Each node has a bunch of data associated with it, but as far as this question goes, I just want a way to represent a tree visually using Python. Any ideas?

The different solutions that popped in my head were to use a GUI library like WxPython or PyQT, or maybe even a PDF generator like ReportLab. I'm hoping there's a library out there that deals closer with data so that I don't have to think out the plotting locations of all the nodes.

+5  A: 

Not sure if this is applicable to your situation, but have you looked at graphviz? It has decent python bindings for it and I've used it for visualizing dependencies which sometimes end up looking like trees.

Mattias Nilsson
Very cool! Just what I was looking for thanks.
A: 

Consider using a textual representation of the tree. Otherwise, I'd go with graphviz (dotty, actually).

[root]
+------child1
+------child2
    +-------child3
    +-------child4

To show the same tree in graphviz, put this in a text file:

digraph graphname {
    root -> child1;
    root -> child2;
    child2 -> child3;
    child2 -> child4;
}

Then run dotty on it, or your tool or choice.

Steve Hanov
+2  A: 

Instead of using graphviz directly, consider using the visualization tools included in NetworkX. The graph objects there are excellent for many purposes.

Gregg Lind
Images look great too.