GenerateurGraphe.py

Laurent Mon, 11/02/2024 02:59 pm

Download (1 kB)

 
1
from networkx import *
2
import matplotlib.pyplot as plt
3
from random import sample,randint
4
5
liste_Personnes = ["Al","Be","Ch","Do","Em","Fa","Gu","He","Is","Ja","Ke","Lo","Ma","Ni","Od","Pi","Qu","Ro","Su","Ta","Ur","Ve","Wa","Xa","Yv","Zo"]
6
amis=sample(liste_Personnes[3:10],4)
7
8
reseau_social=Graph()
9
for personne in amis :
10
    reseau_social.add_node(personne)
11
    for relie in sample(liste_Personnes[5:14],(randint(2,6))):
12
        if relie != personne:
13
            reseau_social.add_edge(personne,relie)
14
15
couleurs=[["pink","red"],["lightblue","blue"],["lightgreen","green"],["yellow","orange"]]
16
#couleur=couleurs[randint(0,len(couleurs)-1)]
17
couleur=couleurs[1]
18
options = {
19
    "font_size": 12,
20
    "node_size": 1000,
21
    "node_color": couleur[0],
22
    "edgecolors": couleur[1],
23
    "linewidths": 2,
24
    "width": 2,
25
}
26
position = circular_layout(reseau_social)
27
28
print("Diametre=",diameter(reseau_social))
29
print("Rayon=",radius(reseau_social))
30
print("Centre=",center(reseau_social))
31
draw(reseau_social,pos=position, with_labels=True,**options)
32
plt.draw()
33
plt.show()