** In research that makes full use of scientific and technical calculations, the isosurface of scalar functions is often investigated. ** ** Doing this with standard plots using matplotlib alone may not be easy (or perhaps not possible at this time).
** On the other hand, using mayavi allows you to quickly draw an isosurface. mayavi is (apparently) known as an excellent 3D visualization library for presentations, conference presentations, and dissertations [1]. ** **
Here, as an example of drawing the isosurface using mayavi, the isosurface of the trigonometric function $ f (x, y, z) = \ frac {\ sin (xyz)} {(xyz)} \ tag 1 $ Try to draw [1,2].
A lot of information is posted on mayavi's official website, and this article follows it.
(1) Draw four isosurfaces by dividing the possible values of f into four equal parts.
(2) Draw a cross section of the isosurface.
"""
Draw a 3D isosurface using mayavi: iso-surface
30 Aug. 2017
"""
import numpy as np
from mayavi import mlab
mlab.init_notebook() #Notebook initialization. Be sure to put it in.
x, y, z = np.ogrid[-5:5:64j, -5:5:64j, -5:5:64j]
scalar = np.sin(x*y*z)/(x*y*z) #Function settings
#Generation of drawing area
mlab.figure(1, bgcolor=(1, 1, 1), fgcolor=(0, 0, 0), size=(600, 400)) #Set background color, size, etc.
mlab.clf()
#Draw a 3D isosurface. Set colormap to jet, contours is the number of divisions, line_width is line thickness, opacity is opacity(The default is 1.0)
obj=mlab.contour3d(scalar,colormap='jet',\
contours=4,line_width=1.3,opacity=0.8)
mlab.show()
obj #Finally run the drawing object! If you don't do this, nothing happens.
"""
Draw a cross section of the 3D isosurface using mayavi:
"""
import numpy as np
from mayavi import mlab
mlab.init_notebook()
x, y, z = np.ogrid[-5:5:64j, -5:5:64j, -5:5:64j]
scalar = np.sin(x*y*z)/(x*y*z)
#Cross section setting:Create objects with cross sections parallel to the x-axis and y-axis with the names ss1 and ss2
ss1=mlab.pipeline.image_plane_widget(mlab.pipeline.scalar_field(scalar),plane_orientation='x_axes',slice_index=10,)
ss2=mlab.pipeline.image_plane_widget(mlab.pipeline.scalar_field(scalar),plane_orientation='y_axes',slice_index=10,)
mlab.show()
ss1
ss2
My machine environment: macOS Sierra 10.12.6 Start the terminal and
And said.
When starting Jupyter-notebook 5.0 or later, ** iopub_data_rate_limit must be set large, otherwise the memory required for drawing using mayavi will be insufficient **. Therefore, when starting jupyter, it seems necessary to set *** jupyter-notebook --NotebookApp.iopub_data_rate_limit = 10000000000 *** etc. [4].
[1] miyavi tutorial: http://docs.enthought.com/mayavi/mayavi/auto/mlab_helper_functions.html [2] About contour3d (English) http://mdns.esy.es/2017/06/17/contour3d/
[3] Qiita article by 2dod, Settings when using Mayavi with Jupyter notebook [4] Regarding iopub_data_rate_limit (English): https://github.com/jupyter/notebook/issues/2287