Search code examples
networkx

using draw_networkx(), How to show multiple drawing windows?


The following code will create only one window at a time, the second window will only show when the first one is closed by the user.

How to show them at the same time with different titles?

nx.draw_networkx(..a..)
nx.draw_networkx(..b..)

Solution

  • It works the same as making other plots with Matplotlib. Use the figure() command to switch to a new figure.

    import networkx as nx
    import matplotlib.pyplot as plt
        
    G=nx.cycle_graph(4)
    H=nx.path_graph(4)
    
    plt.figure(1)
    nx.draw(G)
    plt.figure(2)
    nx.draw(H)
        
    plt.show()