Hello, I'm new in Matplotlib and am writing in order to ask a help. I've developed a little software with Python that, by inserting a number, calculate a list of couples. Example Insert a number: 4 Couples: [[4, 3], [4, 2], [4, 1], [3, 2], [3, 1], [2, 1]] What I'd like to do is drawing with Matplotlib a graph having as nodes 1, 2, 3, 4 and as edges among the nodes the above couples. (sample drawing: https://networkx.lanl.gov/) Can you help me to make this operation please? My code at the present is the following one. n = input("Insert a number" ) a = range(n) p = 0 q = 1 coppie = [] coppia = [] while len(a) - p != 1: coppia.append(len(a) - p) coppia.append(len(a) - p - q) coppie.append(coppia) coppia = [] if len(a) - p - q != 0: q = q + 1 if len(a) - p - q == 0: p = p + 1 q = 1 print coppie I suppose it is quite easy but in spite of this have some difficulty. Really many thanks for the help! Best, Nico
On 2006年5月26日, Giandomenico Sica apparently wrote: > Insert a number: 4 > Couples: [[4, 3], [4, 2], [4, 1], [3, 2], [3, 1], [2, 1]] > What I'd like to do is drawing with Matplotlib a graph having as nodes > 1, 2, 3, 4 and as edges among the nodes the above couples. n = input("Insert a number" ) a = reversed(range(1,n+1)) coppie = [[i,j] for i in a for j in range(1,i)] print coppie G = NX.Graph() for edge in coppie: G.add_edge(*edge) print G.edges() NX.draw(G) pylab.savefig(r'c:\temp\temp.eps') hth, Alan Isaac