Ask Your Question
0

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:

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 15:38:05 +0200

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 09:16:32 +0200

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 13:22:52 +0200

Seen: 681 times

Last updated: Mar 31 '14