index out of bounds if X not equals to y

hi all
I have a little script who just plot some tripet (random triplet) but I have a index out of bound

What I don’t understand is if Xl is diff of Yl , I have that error
Traceback (most recent call last):

File “test_plot3D.py”, line 26, in
ax.plot_wireframe(X, Y, Z)
File “/usr/lib/python2.5/site-packages/matplotlib/axes3d.py”, line 562, in plot_wireframe
txlines = [tX[i] for i in cii]

IndexError: index out of bounds

if there equals, all is perfect, but I haven’t that.

there is the script

import numpy
import pylab as p
import matplotlib.axes3d as p3
import random

data = []
Xl = 10
Yl = 40 #if Yl = Xl , all is ok

#create data
for i in range(Xl):
for j in range(Yl):
data.append( (i,j,int( random.random()*10 ) ) )

X, Y = numpy.meshgrid(p.arange(0, Xl, 1), p.arange(0, Yl, 1))
Z = numpy.zeros( (Xl, Yl) )
for d in data:
x, y, z = d
Z[x, y] = z

fig = p.figure()
ax = p3.Axes3D(fig)
ax.plot_wireframe(X, Y, Z)

p.show()

any help.

thanks.

a++

Hi,
Just some quick comments:

1. learn list comprehensions, they're far faster than regular loops.

data = [(i,j,int(numpy.random.random()*10))
               for i in range(XI) for j in range(JI)]

2. if you don't really need the triplets, but just the random part, just use:
Z = (numpy.random.random(XI*YI)*10).astype(int).reshape(Xl,Yl)

3. It's more efficient to use numpy.empty than numpy.zeros to initialize an
array you're going to fill afterwards.

4. You may have found a bug in plot_wireframe, actually. The code doesn't look
quite right. My understanding is that the 3d part is not really supported,
either...

Hope it helps.

···

On Wednesday 11 April 2007 03:28:09 elekis wrote: