I am trying to use graph-tool to graph a network graph with coloured vertices. I am trying to graph the following graphML file from here shown below.
However, the colour are not showing with the following code:
g = Graph()
g= load_graph("filename.graphml", fmt="graphml")
graph_draw(g)
The graph renders but there are no colours on vertices, only for default red. I thought that graphML was fully supported?
Graph-tool docs states: "The only file formats which are capable of perfectly preserving the internal property maps are “gt” and “graphml”. Because of this, they should be preferred over the other formats whenever possible."
Is colour not an internal property?
Oringinally I was graphing in DOT. I have an array of colours the index of which depends on name of the node - the nodes are integers in increasing order. However, when I was using:
for v in g.vertices():
v_prop[v] = colourarray[vertex]
The colours did not correspond to the correct node. This is due to the fact the load_graph seems to have its own idea of which nodes are which index. Does any one have an idea of what I can do here?
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<key id="d0" for="node" attr.name="color" attr.type="string">
<default>yellow</default>
</key>
<key id="d1" for="edge" attr.name="weight" attr.type="double"/>
<graph id="G" edgedefault="undirected">
<node id="n0">
<data key="d0">green</data>
</node>
<node id="n1"/>
<node id="n2">
<data key="d0">blue</data>
</node>
<node id="n3">
<data key="d0">red</data>
</node>
<node id="n4"/>
<node id="n5">
<data key="d0">turquoise</data>
</node>
<edge id="e0" source="n0" target="n2">
<data key="d1">1.0</data>
</edge>
<edge id="e1" source="n0" target="n1">
<data key="d1">1.0</data>
</edge>
<edge id="e2" source="n1" target="n3">
<data key="d1">2.0</data>
</edge>
<edge id="e3" source="n3" target="n2"/>
<edge id="e4" source="n2" target="n4"/>
<edge id="e5" source="n3" target="n5"/>
<edge id="e6" source="n5" target="n4">
<data key="d1">1.1</data>
</edge>
</graph>
</graphml>