Reputation: 111
I have the following code using pygraphviz on Google colab. How do I see the output graph? This is similar to [this question][1], except for the fact that the solution only works for graphviz, and not pygraphviz.
import pygraphviz as pgz
def tocolor(u):
assert u >= 0
assert u <= 1
z = int((1-u)*256)
return '#%2x%2x%2x'%(z,z,z)
#return '#%2x%2x%2x'%(int(u*256),100,int((1-u)*256))
def drawG(filename,nodes,c,directed=False):
n = len(nodes)
G = pgz.AGraph(strict=True, directed=directed)
G.node_attr['shape']='circle'
#G.node_attr['style']='filled'
for x in range(n):
#G.add_node(nodes[x],fillcolor=".6 .1 .1")
G.add_node(nodes[x])
for i in range(n):
for j in range(i+1,n):
if c[i,j] < 1e-3:
continue
else:
u = c[i,j]/100
G.add_edge(nodes[i],nodes[j],color=tocolor(u),style="setlinewidth(4)")
G.draw(filename,prog='circo',args='-Gsize="200,200"')
l='Cervix,Vagina,Uterus,Iliac LN,Mandibular LN,Mesenteric LN,Axillary LN,Bronchial LN,Colonic LN,Colon,Spleen,Rectum,Inguinal,Liver,Ovary,Bone Marrow'
l = l.split(',')
y = pylab.loadtxt('Matrix.csv',dtype=float,usecols=list(range(1,17)),delimiter=',')
def main():
drawG('example-graph.pdf',l,y)
main() ```
[1]: https://stackoverflow.com/questions/59560168/graphviz-not-printing-output-graph-on-colab
Upvotes: 0
Views: 99
Reputation: 56
This import seems to be missing.
import pylab
but other than than, what error are you getting?
Upvotes: 1