How to draw an ordered tree in python?
Question: I have an XML file whose underlying structure is an ordered tree. I use
digraph in networks representing this tree and then I want to draw this tree.
Suppose the digraph is G, then I write the following code:

    
    
    map = dict(zip(id,tag)) # map from id to label
    pos = nx.pydot_layout(G,prog = 'dot')
    labels = nx.draw_networkx_labels(G, pos, map) 
    nx.draw_networkx(G, pos, False, node_size = 1000, node_color = color)
    plt.show()
    

but i cannot get a ordered tree. the order of silbing nodes are not in their
original order.

I want to know how can I plot an ordered tree in python, thanks,


Answer: Don't call a variable `map`, there is a builtin called `map`.

You can use an
[OrderedDict](http://docs.python.org/library/collections.html#collections.OrderedDict)
to keep the items in order:

    
    
    from collections import OrderedDict
    from itertools import izip
    themap = OrderedDict(izip(id,tag)) # map from id to label
    

You can also [get it from PyPI](http://pypi.python.org/pypi/ordereddict) if
you have an older version of Python than 2.7 / 3.2.

