Ask Your Question

Plotting Grid Graph

asked 2014-02-16 13:22:52 +0200

jaia gravatar image

updated 2015-01-17 22:26:13 +0200

FrédéricC gravatar image

I'm trying to plot a grid graph, specifying exactly where vertices should be plotted. (I want the plot to look like an actual grid and later overlay a graphics object on it.) The following code gives a KeyError:

pos_list=[(i,j) for i in range(8) for j in range(12)]
for i in range(len(pos_list)):

How can I get my plot to look like a regular grid?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2014-02-16 15:38:05 +0200

fidbc gravatar image

How about assigning the vertex itself as the position?

G=graphs.GridGraph([8,12])[(v,v) for v in G.vertices()]))
edit flag offensive delete link more

answered 2014-03-31 09:16:32 +0200

alejandroerickson gravatar image

You might want to adjust the spacing or label size with the figsize option:[10,10],pos=dict([(v,v) for v in G.vertices()]))

or store the positions as a property of the graph with

G.set_pos(dict([(v,v) for v in G.vertices()])) 
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2014-02-16 13:22:52 +0200

Seen: 697 times

Last updated: Mar 31 '14