How to create a connected graph in networkx
I want to create a connected graph in IPython
laptop via NetworkX
. I used to use
erdos_renyi_graph
to generate a random graph, but I never get a connected graph, I want to use this graph to prove that my graph is a small world network. But the non-viscous graph of the shortest shortest graph cannot be calculated. So please tell me how to create a linked graph via NetworkX
.
source to share
As you did not specify the exact parameters of your graph, I want to suggest playing with the probability of creating edges. The following function networkx allows you to provide the probability (p) for an edge to exist on the graph.
erdos_renyi_graph(n, p, seed=None, directed=False)
As an example:
G = nx.erdos_renyi_graph(500, 0.5, seed=123, directed=False)
provides you with a fully connected schedule.
source to share
There are many graph generators forNetworkX
, you can use not only erdos_renyi_graph
(which can be adjusted to almost the second parameter):
Social media for you:
-
karate_club_graph()
- Return the Earl of the club to Zachariya Karat . -
davis_southern_women_graph()
- Return South Davis Women's Social Network . -
florentine_families_graph()
- Return the schedule of the Florentine families .
-
caveman_graph(l, k)
- Returns the caveman graph byl
click sizek
. -
connected_caveman_graph(l, k)
- Returns the linked caveman graph byn
click sizek
. -
relaxed_caveman_graph(l, k, p[, seed, directed])
- Bring back a relaxed caveman schedule . -
random_partition_graph(sizes, p_in, p_out[, ...])
- Return a custom graph of sections with section sizes. -
planted_partition_graph(l, k, p_in, p_out[, ...])
- We return the plantedl
-size chart . -
gaussian_random_partition_graph(n, s, v, ...)
- Create a Gaussian graph of random splits . -
ring_of_cliques
etc.
source to share