0

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>
Tiago Peixoto
  • 5,149
  • 2
  • 28
  • 28
Gawnie
  • 121
  • 4

1 Answers1

0

You are conflating the existence of a property map with it actually being used for drawing. If you want to use a property map, you have to do so explicitly:

graph_draw(g, vertex_fill_color=g.vp.color)

Please take a look at the documentation, which contains many examples of this kind.

The inherent vertex "names" that exist in dot and graphml files are loaded as internal property maps. In the case of dot, the property map is named "vertex_name":

g.vp.vertex_name

in the case of graphml, if the vertex label is not canonical (i.e. numbered from 0 to N-1), it is stored as "_graphml_vertex_id":

g.vp._graphml_vertex_id
Tiago Peixoto
  • 5,149
  • 2
  • 28
  • 28
  • I still do not understand how I can create a property map with the vertices identified as the integer passed to them. If my input DOT file looks like: 1 2 3 1 -> 3 then do I have to create a property name to define their names? How do I do this if then the iterator does not follow this ordering? Can you please point me to these examples? – Gawnie Aug 12 '17 at 11:03
  • @Gawnie I have edited the answer to address your question. – Tiago Peixoto Aug 15 '17 at 10:44