Dear ALL,
I want to plot lines ("edges") between a sequence of points ("nodes"),
using the following code:
from pylab import *
import matplotlib.pyplot as plt
nodes = load('nodes.dat')
edges = load('edges.dat')
n = nodes.shape[0]
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
plt.plot(nodes[:,0],nodes[:,1],'ob')
for i in range(n):
try:
t = edges[i,0]-1
u = edges[i,1]-1
x = [nodes[t,0], nodes[u,0]]
y = [nodes[t,1], nodes[u,1]]
plot(x,y,'-b')
except:
continue
plt.show()
And here are the "nodes.dat"
-61.05 10.4
-79.4333333333 9.15
-70.6666666667 9.53333333333
-63.1166666667 7.91666666667
-63.1166666667 10.55
-81.1833333333 7.51666666667
-56.4833333333 3.1
-60.5 3.93333333333
-81.0166666667 7.66666666667
-67.4333333333 8.93333333333
-65.9666666667 10.3166666667
-78.9333333333 8.38333333333
-72.8666666667 9.83333333333
-68.4 10.6166666667
-72.9833333333 10.6166666667
...and "edges.dat" files:
1 5
4 5
5 11
10 11
10 14
3 14
3 13
13 15
4 8
7 8
12 13
2 12
2 9
6 9
The above code works quite well. However, I do *not* want to have the
plot done for each edge inside the for loop; instead, I would like to
have the x,y points stored for being plotted at once, using a plot
command issued outside the loop. It seems that it could be done using
MPL line collections, but I could not figure out how to do this. Any
hints?
Thanks in advance for any assistance you can provide.
With best regards,
···
--
Dr. Mauro J. Cavalcanti
Ecoinformatics Studio
P.O. Box 46521, CEP 20551-970
Rio de Janeiro, RJ, BRASIL
E-mail: maurobio@...287...
Web: http://studio.infobio.net
Linux Registered User #473524 * Ubuntu User #22717
"Life is complex. It consists of real and imaginary parts."