import networkx as nx import matplotlib.pyplot as plt g = nx.Graph() # Creates a graph edges_file = open("states_border_edges.txt") for line in edges_file: cities = line.split(",") # split the line, dividing up by commas # add the two cities as a new edge in the graph g.add_edge(cities[0].strip(), cities[1].strip()) g.add_edge("Idaho", "Utah") g.add_edge("Oregon", "Idaho") g.remove_edge("Washington", "Utah") g.add_edge("California", "Nevada") g.add_edge("Nevada", "Utah") nx.draw_networkx(g) # Draw the graph plt.show() # Show the graph