秉着边学边写边折腾的原则,开始粗糙的工作。真正掌握还是得讲解给别人听。 先给出网课
https://www.icourse163.org/course/BIT-1001871001
Mayavi官方
http://docs.enthought.com/mayavi/mayavi/genindex.html
(有时候这网站会装死,一般过几个小时就会活过来)
写在前面:
imshow
,plot3d
放在一起讲,是因为它们的参数很相近,之前的mesh
和triangular_mesh
也是如此,只不过它们的参数是完全一致。imshow
具备interpolate
参数,而plot3d
具备representation
参数。
这节内容是很少的~
1.imshow
老规矩从官方例子开始,先微调一下官方代码
import numpy as np
from mayavi.mlab import *
s = np.random.random((10, 10))
imshow(s, colormap='gist_earth')
show()
得到一张地毯
np.random.random((10, 10))
得到了一个10X10的矩阵赋给了s
我们来看
imshow(s, ...)
这个语法,接受的是s
s is a 2 dimension array. The values of s are mapped to a color using the colormap.
s是一个二维
array
,官方例子中给出是10X10的大小,映射方式按照的是s
的值的大小。
这个绘图函数应该算是很简单的一个,不过更有意思的是那个colormap
参数,以后有机会会说到。
2.plot3d
基本语法如下:
plot3d(x, y, z, ...)
plot3d(x, y, z, s, ...)
官方实例
import numpy as np
from mayavi.mlab import *
"""Generates a pretty set of lines."""
n_mer, n_long = 6, 11
dphi = np.pi / 1000.0
phi = np.arange(0.0, 2 * np.pi + 0.5 * dphi, dphi)
mu = phi * n_mer
x = np.cos(mu) * (1 + np.cos(n_long * mu / n_mer) * 0.5)
y = np.sin(mu) * (1 + np.cos(n_long * mu / n_mer) * 0.5)
z = np.sin(n_long * mu / n_mer) * 0.5
l = plot3d(x, y, z, np.sin(mu), tube_radius=0.025, colormap='Spectral')
show()
这个图的效果如下:
这个图很容易理解
核心的语句
plot3d(x, y, z, np.sin(mu), tube_radius=0.025, colormap='Spectral')
对照官方的文档
plot3d(x, y, z, s, ...)
Draws lines between points.
x, y, z and s are numpy arrays or lists of the same shape. x, y and z give the positions of the successive points of the line. s is an optional scalar value associated with each point.x,y,z以及s为同维度的
array
或list
,x,y,z给定坐标,然后依次连接成为一条连续的直线,s是一个缺省参数,表示每一个点的标量值。
可以说言简意赅了。连点成线,这个也是一个隐性连通,这个好理解。
多提两个地方
tube_radius=0.025
这个线,还不是单纯的线条,不是一维概念,这个线是管,看下细节。
设置representation
,为了防止颜色的干扰,再把s
的标量赋值去掉。
这下就很明显了。
colormap='Spectral'
然后需要注意就是这个配色方案,光谱配色直译即可。
3.imshow
以及plot3d
的参数
imshow
interpolate
if the pixels in the image are to be interpolated or not. Must be a boolean. Default: True
图像中的像素是否允许被插值,接受布尔值,默认值为True
这是一个插值开关,我们来试试效果。
左边的设置为
True
,右边的设置为False
右边很马赛克。。。
这也是imshow
最特殊的一个地方,12个绘图函数中只有imshow
具有这个功能
plot3d
representation
the representation type used for the surface. Must be ‘surface’ or ‘wireframe’ or ‘points’. Default: surface
这个参数是一个很常用的参数,imshow
不具备这个参数,它们的绘制方式不同。可以用来观察绘制的细节,开始为了说明tube_radius
的时候引用就用了representation
来观察细节。
tube_radius
radius of the tubes used to represent the lines, If None, simple lines are used.
这个参数也已经在上面进行了说明。这是一个缺省值,默认0.025,需要注意的是
None
的效果,如果是None
的话,就是一根线,没有粗细的线。放大和缩小不会对它产生任何效果。
线径粗细是完全一样的。
.
对于管线中的变化,Tube
消失了,这个层级中是没有Line width
选项的,也就是单纯的线了。
只要tube_radius
不是None
就会出现Tube
层级,并且可以为其设置线径。
tube_sides
number of sides of the tubes used to represent the lines. Must be an integer (int or long). Default: 6
这个参数表达的是绘制的tube_radius
的数目,mesh
的文章中讲过,这里改个图。需要注意这个值要大于等于3,否则报错,这是可以理解的。
我取了比较极端的情况,整个就是一根三角形管道,后者是10边形管道。
这个可以理解为管道分辨率,前面都提到过了,这个不再多说了。
更新(18.10.10已更完)
2018.10-10.——一次更完。