First time here? Check out the FAQ!

Ask Your Question
0

Plotting Grid Graph

asked 11 years ago

jaia gravatar image

updated 10 years ago

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?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
1

answered 11 years ago

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()]))
Preview: (hide)
link
0

answered 10 years ago

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()
Preview: (hide)
link

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: 11 years ago

Seen: 809 times

Last updated: Mar 31 '14