IPython est un excellent outil pour découvrir ce que les fonctions (et les objets) peuvent faire. Si vous tapez
[1]: import networkx as nx
[2]: nx.draw?
vous voyez
Définition: nx.draw (G, pos = Aucun, ax = Aucun, maintenez = Aucun, ** kwds)
**kwds: optional keywords
See networkx.draw_networkx() for a description of optional keywords.
Et si vous tapez donc
vous allez voir
node_color: color string, or array of floats
edge_color: color string, or array of floats
width: float
Line width of edges (default =1.0)
labels: dictionary
Node labels in a dictionary keyed by node of text labels (default=None)
Armé de ces informations, et un peu d'expérimentation, il est difficile de ne pas arriver à:
import matplotlib.pyplot as plt
import numpy as np
import networkx as nx
import string
G = nx.generators.erdos_renyi_graph(18, 0.2)
nx.draw(G,
node_color = np.linspace(0,1,len(G.nodes())),
edge_color = np.linspace(0,1,len(G.edges())),
width = 3.0,
labels = {n:l for n,l in zip(G.nodes(),string.ascii_uppercase)}
)
plt.show()
qui donne
http: // networkx.lanl.gov/reference/drawing.html - vous voulez les fonctions 'draw_networkx_edges' et' draw_networkx_nodes' – job