import networkx as nx import matplotlib.pyplot as plt # read in the graph G = nx.read_gpickle('major_us_cities') # In[15]: # draw the graph using the default spring layout plt.figure(figsize=(10, 9)) nx.draw_networkx(G) # In[16]: # See what layouts are available in networkX [x for x in nx.__dir__() if x.endswith('_layout')] # In[17]: # Draw the graph using the random layout plt.figure(figsize=(10, 9)) pos = nx.random_layout(G) nx.draw_networkx(G, pos) # In[18]: # Draw the graph using the circular layout plt.figure(figsize=(10, 9)) pos = nx.circular_layout(G) nx.draw_networkx(G, pos)
# Visualizing Networks import networkx as nx import matplotlib.pyplot as plt # Read the graph G = nx.read_gpickle('major_us_cities') # Have a look at the data print(G.nodes(data=True)[0]) print(G.edges(data=True)[0]) # Have a look at different layouts in networkx print('Layouts:', [layout for layout in nx.__dir__() if layout.endswith('_layout')]) ####################################################################################### # ==> 1. Default Spring Layout plt.figure(figsize=(10, 7)) nx.draw_networkx(G) # ==> 2. Random Layout plt.figure(figsize=(10, 7)) nx.draw_networkx(G, pos=nx.random_layout(G)) # ==> 3. Circular layout plt.figure(figsize=(10, 7)) nx.draw_networkx(G, pos=nx.circular_layout(G)) # ==> 4. Spectral layout