Reputation: 1989
I am making a 3D contour plot of some volumetric data using mlab
from the Mayavi module. I would like to draw a box with the axes around that plot, but I am only able to get one x-axis, one y-axis, and one z-axis. The axes opposite of those axes are not drawn. How do I get those missing axes?
Here is my code:
import matplotlib.pyplot as plt
from mayavi import mlab
import numpy as np
import matplotlib
import mayavi
import sys
# check versions
print( 'matplotlib version: ', matplotlib.__version__ )
print( 'mayavi version : ', mayavi.__version__ )
print( 'numpy version : ', np.__version__ )
print( 'python version : ', sys.version_info )
# create the grid
x = np.linspace(0,np.pi,100)
y = np.linspace(0,2*np.pi,200)
z = np.linspace(0,2*np.pi,400)
X, Y, Z = np.meshgrid(x, y, z)
# create the data to be plotted
dat = np.cos(X) * np.sin(Y) * np.cos(Z)
# make a 3D contour plot
mlab.contour3d(dat)
ax1 = mlab.axes( color=(1,1,1), nb_labels=4 )
mlab.show()
The output of the version check is as follows:
matplotlib version: 3.5.0
mayavi version : 4.7.4
numpy version : 1.21.4
python version : sys.version_info(major=3, minor=8, micro=10, releaselevel='final', serial=0)
And, finally, the image, where it can be seen clearly that there is no full box surrounding the plot:
Upvotes: 0
Views: 972
Reputation: 1989
The answer is actually quite simple: mlab.outline()
. One has to replace the contour plotting part with the following code:
# make a 3D contour plot
cont3d = mlab.contour3d(dat)
ax1 = mlab.axes( color=(1,1,1), nb_labels=4 )
mlab.outline(cont3d)
mlab.show()
Upvotes: 0