Using networkx to show graph on pycharm

Viewed 417

I am trying to draw a random network on a python file in pycharm but I am not getting anything when I run the file except for 'Process finished with exit code 0'. I am suppose to get a drawing of the network through nx.draw() command but for some reason its not working. My code shows no error, here is my code:

import networkx as nx

N = 10

m = 2

G = nx.barabasi_albert_graph(N, m)

nx.draw(G)

I also tried the following code:

import networkx as nx

N = 10

m = 2

G = nx.barabasi_albert_graph(N, m)

nx.draw_networkx(G)

I would really appreciate if someone could help.

1 Answers

you can draw a graph using :

import networkx as nx

import matplotlib.pyplot as plt

g = nx.Graph()

g.add_edge(1, 2)
g.add_edge(2, 3)
g.add_edge(3, 4)
g.add_edge(1, 4)
g.add_edge(1, 5)

nx.draw(g)
plt.savefig("filename.png")
Related