Playing wit MayaVi, I cannot display mesh with the following code. What could be wrong?

def visualize_surf(self):
    times = self.retT[imin:imax]
    nrows = (int)((times[(len(times)-1)] - times[0])/self.mod) + 1

    x = []
    for i in range(nrows):
        x.append(self.matRetT[i][0] + self.mod * i)

    y = []
    for i in range(len(self.matRetT[0])):
        y.append(self.matRetT[0][i])
    y = y[:-1]

    X,Y = np.meshgrid(x,y)

    z = [tuple(self.mat[i]) for i in range(len(self.mat))]

    Zzip = zip(*z)
    Z = [list(x) for x in Zzip]

    return mlab.mesh(Y,X,Z) 

There is no display -> could this be that I miss a command like -wthread in IPython shell? however modality is said to be turned on by default.

X,Y,Z have same size, there is no warning or exception, and MayaVi scene 1 does open but remains empty.

This could be a problem with meshgrid, a problem with arguments desirable in mesh. However reading through the doc, I cannot find out.

有帮助吗?

解决方案

Matplotlib's "plot_surface" and Mayavi's "surf" follow different logics. As indicated in Mayavi's documentation, the result of meshgrid should be transposed to fit Mayavi's requirements.

Also, one should be careful when using Matplotlib functions like griddata in combination with Mayavi, because its results assume Matplotlib's kind of meshgrid. griddata's fourth and fifth arguments should be switched to fit Mayavi.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top