4

Good evening everyone, I am a long time user of Matplotlib and I recently discovered Mayavi.

With Matplotlib, I can plot a 3D surface with projected contours of the surface plot for each axis and I was wondering if the same could be done with Mayavi.

Here is an example of what I have done so far with Matplotlib (source), but I have not been able to find a similar way to plot contours with Mayavi on the internet:

enter image description here

Can someone who knows Mayavi tell me if I can plot 3D contours for each axis like with Matplotlib?


Matplotlib code

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm

fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y, Z = axes3d.get_test_data(0.05)
ax.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3)
cset = ax.contour(X, Y, Z, zdir='z', offset=-100, cmap=cm.coolwarm)
cset = ax.contour(X, Y, Z, zdir='x', offset=-40, cmap=cm.coolwarm)
cset = ax.contour(X, Y, Z, zdir='y', offset=40, cmap=cm.coolwarm)

ax.set_xlabel('X')
ax.set_xlim(-40, 40)
ax.set_ylabel('Y')
ax.set_ylim(-40, 40)
ax.set_zlabel('Z')
ax.set_zlim(-100, 100)

plt.show()

Mayavi code

from mpl_toolkits.mplot3d import axes3d
from mayavi import mlab

X, Y, Z = axes3d.get_test_data(0.05)

Z = np.rollaxis(Z,0,2)
X = np.rollaxis(X,0,2)
Y = np.rollaxis(Y,0,2)

mlab.surf(X, Y, Z, warp_scale="auto", opacity=1)
mlab.axes(xlabel='X', ylabel='Y', zlabel='Z')
mlab.show()
Loïc Poncin
  • 511
  • 1
  • 11
  • 30
  • 1
    Mayavi can calculate three-dimensional contours, but I do not think that the projection of those contours onto specific planes is implemented. You probably have to do it manually. – Patol75 Jun 07 '19 at 04:18

0 Answers0