nodes with lat and long

1,138 views
Skip to first unread message

Sergio Hernández López

unread,
Jan 3, 2011, 12:24:10 AM1/3/11
to networkx-discuss
Hi all

I need to make a graph where the nodes belongs to a geographical
space, that is, I need them to keep the distribution observed in a map
using their latitude and longitude. I want to know if there's a way to
do this with networkx

Thanks for the attention and greetings.



Sergio Hernandez

Dan Schult

unread,
Jan 3, 2011, 10:00:09 AM1/3/11
to networkx...@googlegroups.com
You can store node attributes using the G.node dictionary,
or when the node is created using keyword arguments to G.add_node()

G=networkx.Graph()
G.add_node(1,lat=40.5,long=42.5)
#or
G.add_node(1,pos=(40.5,42.5))
print G.node[1]
{'lat': 40.5, 'long': 42.5, 'pos': (45.5, 42.5)}

You might also take a look at the following thread that talks
about using matplotlib to draw the nodes on a map:
http://groups.google.com/group/networkx-discuss/browse_thread/thread/f52bff0b3eb0b086

Dan

franck kalala

unread,
Jan 3, 2011, 10:12:50 AM1/3/11
to networkx...@googlegroups.com
Hi All,

Is there any routine in here that can generate two (connected or no) random
graph connected by a path?
In a similar way as for the function
"barbell_graph(m1, m2, create_using=None)"

I need K_{m1} be two random graph of the same size not necessary identical,
for example two erdos_renyi or two barabasi albert,

Cheers

----- Message d'origine ----
De : Dan Schult <dsc...@colgate.edu>
À : networkx...@googlegroups.com
Envoyé le : Lun 3 janvier 2011, 15h 00min 09s
Objet : Re: [networkx-discuss] nodes with lat and long


Dan

--
You received this message because you are subscribed to the Google Groups
"networkx-discuss" group.
To post to this group, send email to networkx...@googlegroups.com.
To unsubscribe from this group, send email to
networkx-discu...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/networkx-discuss?hl=en.



Dan Schult

unread,
Jan 3, 2011, 10:39:24 AM1/3/11
to networkx...@googlegroups.com
Probably the best approach is to create the two graphs
yourself, then combine with nx.disjoint_union()
and connect one node from each half with a path:
m1=100
A=nx.gnp_random_graph(m1,p=0.1)
B=nx.gnp_random_graph(m1,p=0.1)
C=nx.disjoint_union(A,B)
C.add_path([m1]+range(2*m1,2*m1+m2)+[m1+1])

Dan

franck kalala

unread,
Jan 3, 2011, 10:56:24 AM1/3/11
to networkx...@googlegroups.com
Thx Dan, but m2 is not defined

I set it to m2=1, and visualise the graph, I have two set of random graph but no
path connecting them,

Cheers

----- Message d'origine ----
De : Dan Schult <dsc...@colgate.edu>
À : networkx...@googlegroups.com

Envoyé le : Lun 3 janvier 2011, 15h 39min 24s
Objet : Re: [networkx-discuss] two random graph connected by a path

Dan Schult

unread,
Jan 3, 2011, 10:58:33 AM1/3/11
to networkx...@googlegroups.com
m1 is the number of nodes in each side graph.
m2 is the numder of edges between the two side graphs.
Just like for barbell_graph which I thought you were
trying to mimic.
Reply all
Reply to author
Forward
0 new messages