[Python] Plotting Networkx graph in Python

Discussão em 'Python' iniciado por Stack, Abril 30, 2025.

  1. Stack

    Stack Membro Participativo

    I recently started using networkx library in python to generate and visualize graph plots. I started with a simple code (comprising of 4 nodes) as shown

    import networkx as nx
    import matplotlib.pyplot as plt
    G = nx.Graph()
    G.add_edges_from([(1 ,2) , (2 ,3) , (1 ,3) , (1 ,4) ])
    nx.draw(G)
    plt.show()


    When I run the code for two consecutive times, the outputs for same code is as shown in the images (the orientation of the plot is random)

    [​IMG] [​IMG]

    Is it possible to generate the output of the plots with the same/fixed orientation?

    Continue reading...

Compartilhe esta Página