Eular
Eular

Reputation: 1807

mayavi python surface plot wrong aspect ratio

I'm trying to learn mayavi to plot some 3D data. My xy grid typically looks like this

import numpy 
from mayavi import mlab
x,y = numpy.mgrid[0:90:3j, 0:360:3j]
z= #some calculation
mlab.surf(x, y, z)
mlab.show()

the plot looks like

enter image description here

while the plot using gnuplot looks like this

enter image description here

So, the mayavi image doesn't have proper aspect ratio. How to plot the data properly with mayavi?

Upvotes: 0

Views: 884

Answers (2)

jriege
jriege

Reputation: 31

You can handle that problem by using the extent parameter like this

import numpy 
from mayavi import mlab
x,y = numpy.mgrid[0:90:3j, 0:360:3j]
z= #some calculation
mlab.surf(x, y, z, extent=(0,1,0,1,0,1))
mlab.show()

Upvotes: 3

Patol75
Patol75

Reputation: 4547

The horizontal plane generated by gnuplot produces an axis spanning the range 0-90 which looks at least the same length as the perpendicular axis which spans the range 0-400. Considering this fact, I would tend to say that gnuplot is actually the one for which the aspect ratio is wrong, considering your purpose would be to have somehting similar to the matplotlib call ax.set_aspect('equal', adjustable='box'). Additionally, surf has the warp_scale keyword which allows a vertical exaggeration to be produced. Documentation here.

Upvotes: 1

Related Questions