import numpy
from mayavi import mlab
def lorenz(x, y, z, s=10., r=28., b=8. / 3.):
"""The Lorenz system."""
u = s * (y - x)
v = r * x - y - x * z
w = x * y - b * z
return u, v, w
# 取样.
x, y, z = numpy.mgrid[-50:50:100j, -50:50:100j, -10:60:70j]
u, v, w = lorenz(x, y, z)
fig = mlab.figure(size=(400, 300), bgcolor=(0, 0, 0))
# 用合适的参数画出轨迹的流动.
f = mlab.flow(x, y, z, u, v, w, line_width=3, colormap='Paired')
f.module_manager.scalar_lut_manager.reverse_lut = True
f.stream_tracer.integration_direction = 'both'
f.stream_tracer.maximum_propagation = 200
# 提取特征并绘制
src = f.mlab_source.m_data
e = mlab.pipeline.extract_vector_components(src)
e.component = 'z-component'
zc = mlab.pipeline.iso_surface(e, opacity=0.5, contours=[0, ],
color=(0.6, 1, 0.2))
# 背景设置
zc.actor.property.backface_culling = True
# 图片展示
mlab.view(140, 120, 113, [0.65, 1.5, 27])
mlab.show()