Graphing in a web page

17 views
Skip to first unread message

Eric Breverman

unread,
Jul 15, 2011, 1:21:05 PM7/15/11
to pygraphviz-discuss
Hi, is there a way I can save a graph image to a variable (perhaps
doing something like A.draw(variable, 'png')) and then easily print
the image variable in a web server? I wanted to be able to create
graph's on the fly without having to save them somewhere on my web
server.

Thanks,
Eric

Aric Hagberg

unread,
Jul 15, 2011, 2:42:12 PM7/15/11
to pygraphvi...@googlegroups.com

I'm not sure how you want to send the data to a web server. But you
can e.g. store the png as a string like this:

In [1]: import pygraphviz

In [2]: A=pygraphviz.AGraph()

In [3]: A.add_edge(1,2)

In [4]: A.layout()

In [5]: png=A.draw(format='png')

In [6]: png
Out[6]: '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\xb4\x00\x00\x00L\x02\x03\x00\x00\x00\xb9bu\xd5\x00\x00\x00\x0cPLTE\xfe\xff\xff\xd3\xd3\xd3\x00\x00\x00\xff\xff\xff\\\xa4}\xeb\x00\x00\x00\x01tRNS\x00@\xe6\xd8f\x00\x00\x01\x92IDATH\x89\xed\x96K\xb6\x83
\x0c\x86\xd9\xffRt\xc0\x12\xd8\x0f\x0e\x98\xe39\xf4V+!\xe4\xf1k\xc7\xbd\x19\xf4H\xfa\x19B\xcc\x83\xf0\xfaF\
etc

Aric

Reply all
Reply to author
Forward
0 new messages