[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] writing a layout in a format
From: |
Tamas Nepusz |
Subject: |
Re: [igraph] writing a layout in a format |
Date: |
Mon, 6 Apr 2009 23:25:20 +0100 |
I was wondering if someone could provide an example of how to write
the layout in python.
Well, there are no predetermined layout formats in igraph, so you can
use whatever format suits you the best. If you want to read the layout
from other applications later, it's maybe the best to simply write the
x-y coordinates one per line as follows, e.g.:
g = Graph.GRG(100, 0.2)
layout = g.layout("kk")
fp = file("layout.dat", "w")
for x, y in layout:
print >>fp, x, y
fp.close()
Another way to go is to store the X and Y coordinates as vertex
attributes and then save the graph in a format that preserves vertex
attributes, e.g.:
g = Graph.GRG(100, 0.2)
layout = g.layout("kk")
g.vs["x"], g.vs["y"] = zip(*layout) # ugly but neat trick
g.write("my_graph.graphml")
The same should also work with "my_graph.gml" (using the GML format
instead of GraphML) or "my_graph.pickle" (uses Python's pickle module
instead of GraphML).
You guys need more examples of the simple stuff. :-)
Yes I know ;) The Python docs definitely need some improvement (and I
definitely need some spare time to improve the docs). Sorry about
that. Hope this helps.
--
Tamas
I'm trying to follow the documentation "write(self, f, format =None,
*args, **kwds ) " but I don't know what the heck I'm doing.
Thanks,
- Jeff
_______________________________________________
igraph-help mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/igraph-help