Search code examples
graph-theorydotgephi

How do I set the size of a node in a .dot file?


I want to set the size of my nodes relative to their impact in the graph, and I need to find some way to have their size appear in Gephi. At the moment, I'm using the following code:

def write_graph_dot(graph, filename, label=None):
    g = AGraph(directed=True)
    nodes = set()
    for key in graph:
        if key not in nodes:
            nodes.add(key)
            g.add_node(key, color='red')
            node = g.get_node(key)
            node.attr['fixedsize'] = True
            node.attr['height'] = 1.0
            node.attr['width'] = 1.0
        for value in graph[key]:
            if value not in nodes:
                nodes.add(value)
                g.add_node(key, color='black')
            g.add_edge(key, value, color='black')
    g.write(filename)

When I load this into Gephi, however, the nodes are all the same size. Am I missing something?


Solution

  • This is not possible.

    Subgraphs are not supported, nor custom attributes or size. Only labels and colors are imported if present. Directed and undirected graphs are supported.
    

    https://gephi.org/users/supported-graph-formats/graphviz-dot-format/

    But you can import "size" as a variable, and then use it to set the size in gephi:

     a [label="Foo"];
     a [mysize = 100];
    

    (You have to convert to imported variable from a string to an integer first.)