4
votes

I'm now using python 2.7 and graphviz to draw a cluster-like plot from my data set. Each cluster is represented in this type-->[avg, num] in which "avg" stands for the average value of points in this cluster and "num" stands for the number of points in this cluster

I want to create a plot with each node has different size, which depends on the "num" variable, just like what we can do with networkx

node_sizes = []
for n in nodes:
    node_sizes.append( 100 * n )
g = nx.Graph()
g.add_nodes_from(nodes)
nx.draw_random(g, node_size = node_sizes)

And the reason why I use graphviz but not networkx is because I don't really want to set position of nodes manually, and those engines like neato or circo in graphviz are really helpful.

All comments and help are appreciated. T^T

1

1 Answers

6
votes

You can set the sizes of the nodes as followed:

import graphviz as gv
g = gv.Graph(format='png')
for i in range(5):
    g.node(str(i), **{'width':str(i), 'height':str(i)})
g.render('example')

Which produce:

Graph example