三流Mayavi操作-Mayav-2.1.3-imshow、plot3d绘制

秉着边学边写边折腾的原则,开始粗糙的工作。真正掌握还是得讲解给别人听。 先给出网课
https://www.icourse163.org/course/BIT-1001871001
Mayavi官方
http://docs.enthought.com/mayavi/mayavi/genindex.html
(有时候这网站会装死,一般过几个小时就会活过来)

写在前面:
imshowplot3d放在一起讲,是因为它们的参数很相近,之前的meshtriangular_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为同维度的arraylist,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.——一次更完。

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值