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,
Don't call a variable map
, there is a builtin called map
.
You can use an 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 if you have an older version of Python than 2.7 / 3.2.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.