SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Giandomenico S. <gia...@po...> - 2006年05月26日 11:02:47
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
From: Alan G I. <ai...@am...> - 2006年05月26日 15:00:27
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
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /