Ask Your Question
0

Plotting Grid Graph

asked 2014-02-16 06:22:52 -0500

jaia gravatar image

updated 2015-01-17 15:26:13 -0500

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:

G=graphs.GridGraph([8,12])
pos_list=[(i,j) for i in range(8) for j in range(12)]
pos_dict={}
for i in range(len(pos_list)):
    pos_dict[i]=pos_list[i]
G.show(pos=pos_dict)

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
1

answered 2014-02-16 08:38:05 -0500

fidbc gravatar image

How about assigning the vertex itself as the position?

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

answered 2014-03-31 02:16:32 -0500

alejandroerickson gravatar image

You might want to adjust the spacing or label size with the figsize option:

G.show(figsize=[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()])) 
G.plot()
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

Stats

Asked: 2014-02-16 06:22:52 -0500

Seen: 168 times

Last updated: Mar 31 '14