yEd is a gem of a graph editor that makes it very easy to create diagrams and flowcharts. I used Inkscape for this purpose in the past, and had to do a lot of manual alignment. yEd does it all auto-magically with a very intuitive interface. The only bad thing about it is that it's not open source, although it does come free of charge.
yEd can import graphs from a variety of formats, one of which is GraphML. The other day I had a graph in Python (NetworkX), and I wanted to lay it out nicely for printing. yEd's layout functions surpass anything I've seen Graphviz do, so I decided to export the graph to GraphML and load it into yEd. This proved more difficult than I anticipated, but only because I didn't know where to look. Hopefully this post will save you some time.
Let's generate a graph, give the nodes some labels, and export the graph to a GraphML file:
import networkx as nx
graph = nx.gnp_random_graph(10, 0.13, directed=True)
for node in graph.nodes():
graph.node[node]['label'] = "node %d" % (node + 1)
Now open the
random.graphml file in yEd. All you will see is a square. This
is because all the nodes are on top of each other and have no label. Don't
First, let's recover those labels. If you open the GraphML file in a text editor, you will see that NetworkX was smart enough to export the node labels, but yEd was not smart enough to realize they were labels. In fact, they became properties of the nodes in yEd, which you can see by right-clicking on a node, clicking Properties, and then selecting the Data tab.
And now we come to the part that it took me a long time to figure out. We need to map the "Label" property imported from the GraphML file onto the internal property that yEd uses for labels. To do this, click Edit, Properties Mapper. Click the little plus sign under Configurations, and then 'New Configuration for Nodes.' Now click the plus sign next to 'Mappings'. If you're lucky, yEd should figure out what you're trying to do, and automatically select the right mapping. Your window should look like this:
Now select 'Fit Node to Label' if you want the nodes to be resized to fit the labels, then click OK. (If you forgot to select 'Fit Node to Label,' you can do it later by going to Tools, Fit Node to Label.) You should see the labels now:
But the nodes are still on top of each other. To fix that, use one of the algorithms under the Layout menu. Final result:
Ta-da! If you save the modified graph in GraphML format and open the file in a text editor, you will see that reverse-engineering the format that yEd uses to store labels would not be easy.