三流Mayavi操作-Mayav-2.1.1-图形控制函数 Figure handling functions

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

http://docs.enthought.com/mayavi/mayavi/auto/mlab_figure.html
这个文章我采用全文翻译,而且保留原文的排版风格。中间画蛇添足的方法进行解释吧。
文章分为2节,第一节是翻译,中间例子和讲解。为了解决详略不得当的问题,(以前就是详略不得当)把需要大幅度展开的放在第2节作为补充,并在第1节里面注明扩充的位置。

0.可能用的上的代码

这里给出一段代码<2.1.1-code 0>供调试用:

import numpy as np
from mayavi.mlab import *

x, y, z = np.mgrid[-4:4:40j, -4:4:40j, 0:4:20j]
r = np.sqrt(x ** 2 + y ** 2 + z ** 2 + 0.1)

u = y * np.sin(r) / r
v = -x * np.sin(r) / r
w = np.ones_like(z)*0.05

figure1 = figure(size=(600,600),bgcolor=(1,0,1),figure='Simple 1')
quiver3d(u, v, w,mask_points=20)
xlabel('x')
outline()
flow(u, v, w,linetype='tube',seed_visible=False)
figu = gcf()
# clf(figure1)
clf()
show()

1 全文翻译及讲解

Figure handling functions

clf

mayavi.mlab.clf(figure=None)
Clear the current figure.
You can also supply the figure that you want to clear.
清空当前的figure
你也可以提供想要清理的figure

[画蛇添足]这个是清空当前绘制的内容的一个函数,准确地说不只是清空图像,连数据源也一起清空了
里面可以接受一个参数就是figure

flow(u, v, w,linetype='tube',seed_visible=False)
clf()
clf紧随其后,导致图像连数据源都没了。爽是爽了。就是图有点冷。

在这里插入图片描述

另外figure可以指定。
如果开始赋值了figurehandle

figure1 = figure(size=(600,600),bgcolor=(1,0,1),figure='Simple 1')
那么后面就可以直接用clf(figure1)
得到的效果是完全一样的~
.

.
.

close

mayavi.mlab.close(scene=None, all=False)
Close a figure window
关闭figure窗口。

[画蛇添足]

这个技巧用在集成环境里面。我这里效果体现不多。
如果在show()前面插入close(),这个时候可视化图像就没有了。但是,这一点也是有用的,因为就不用去绘制图形了,跑起来更快了,拿来做计算不知道效果如何。和clf()不一样,这次的数据源还在,没有被清空,可以用其他函数把它调出来。

.
.

draw

mayavi.mlab.draw(figure=None)
Forces a redraw of the current figure.
重新绘制当前figure
.
.

figure

mayavi.mlab.figure(figure=None, bgcolor=None, fgcolor=None, engine=None, size=(400, 350))
Creates a new scene or retrieves an existing scene. If the mayavi engine is not running this also starts it.
创建一个新的scene或者检索存在的scene,如果Mayavi的engine终止了,也可以使用它来开启。

参数:

figure

The name of the figure, or handle to it.
figure的名字,或者handle(有些翻译成句柄,我不想这么翻译,保留专业名词。)

bgcolor:

The color of the background (None is default).
背景色,None是缺省值.
注意缺省值是 (127,127,127),bg是background的缩写。

从GUI里面可以知道
在这里插入图片描述

fgcolor:

The color of the foreground, that is the color of all text annotation labels (axes, orientation axes, scalar bar labels). It should be sufficiently far from bgcolor to see the annotation texts. (None is default).
前景色,所谓前景色指的是所有的文字注释标签(坐标轴,显示标量的标签等),它的颜色应该明显区别于背景色。(默认值是None)

orientation axes我没有翻译,不知道怎么翻译。这个axes和scalar bar labels都是Module层级的内容,属于图形修饰函数,后面会讲,用xlable()可以调出来使用,它能给整个图带上坐标轴。包括scalar bar labels也是一样可以调出来,使用scalarbar(),这里点到为止。这章的内容是图形控制,不是图形修饰。
默认值从上面的GUI里面看的出来,是(225,225,225),也就是白色。

engine:

The mayavi engine that controls the figure.
Mayavi的engine控制所有的figure

这是Mayavi的最高层级,或者是说最底层,看你怎么理解,大概就是老大的性质。GUI里面是不可见的,它用来建立和销毁scene

为了避免内容太冗长,我把engine的内容放在文末作为补充节单独说一下

补充见文末

size:

The size of the scene created, in pixels. May not apply for certain scene viewer.
指定scene创建的交互窗口大小,单位用像素表示。可能不适用于一些场景查看器。
前半句很好理解,后面的场景查看器我没用过,不是很清楚。

场景查看器??留一个坑。

<2.1.1-code 0>里面制定过size的大小,这个size是有默认值的,(400, 350)。确实比较小,如果要做很多大小一样的图,这里就要做点小调整。
figure(size=(600,600),bgcolor=(1,0,1),figure='Simple 1')

.
.

gcf

mayavi.mlab.gcf(engine=None)
Return a handle to the current figure.
You can supply the engine from which you want to retrieve the current figure, if you have several mayavi engines.
返回当前figurehandle
如果存在多个Mayavi engine,你也可以提供你想返回的figureengine

.
.

savefig

mayavi.mlab.savefig(filename, size=None, figure=None, magnification='auto', **kwargs)
Save the current scene. The output format are deduced by the extension to filename. Possibilities are png, jpg, bmp, tiff, ps, eps, pdf, rib (renderman), oogl (geomview), iv (OpenInventor), vrml, obj (wavefront)
存储当前的scene.输出格式将由filename自动判断。可能的扩展名png, jpg, bmp, tiff, ps, eps, pdf, rib (renderman), oogl (geomview), iv (OpenInventor), vrml, obj (wavefront)

参数

这段代码报错!未解决

Size:

the size of the image created (unless magnification is set, in which case it is the size of the window used for rendering).
创建的图像大小.(除非 magnification 已经设定,这种情况下它是渲染的窗口大小。)

Figure:

the figure instance to save to a file.
存储为文件的figure实例

这个可以用gcf捕捉返回handle传进来

Magnification:

the magnification is the scaling between the pixels on the screen, and the pixels in the file saved. If you do not specify it, it will be calculated so that the file is saved with the specified size. If you specify a magnification, Mayavi will use the given size as a screen size, and the file size will be ‘magnification * size’.
Magnification是像素的放缩倍数。如果不指定Magnification参数,它将按照指定的size存储为文件,如果指定,Mayavi会使用给定的size,此时文件的size将会变成 magnification*size

注意

If the size specified is larger than the window size, and no magnification parameter is passed, the magnification of the scene is changed so that the image created has the requested size. Please note that if you are trying to save images with sizes larger than the window size, there will be additional computation cost.
Any extra keyword arguments are passed along to the respective image format’s save method.
.
如果size被指定但是比渲染的窗口大,却没有传入magnification参数,magnification将会发生改变来适应图像被要求的大小来存储。请注意如果你尝试存储图像的大小大于渲染的窗口的大小,将会产生额外的运算量。
所有参数的传入方式应该遵循不同图像格式的存储方式。

.
.

screenshot

mayavi.mlab.screenshot(figure=None, mode='rgb', antialiased=False)
Return the current figure pixmap as an array.

参数

Figure:

a figure instance or None, optional If specified, the figure instance to capture the view of.
接受一个figure实例或者None,如果指定了参数,这figure实例的图像将会被捕捉

Mode:

{‘rgb’, ‘rgba’} The color mode of the array captured.
接受{‘rgb’, ‘rgba’} ,捕获的色彩模式。

Antialiased:

{True, False} Use anti-aliasing for rendering the screenshot. Uses the number of aa frames set by figure.scene.anti_aliasing_frames
接受{True, False},对screenshot的渲染图像使用反锯齿 。

这里没说清楚

Notes

On most systems, this works similarly to taking a screenshot of the rendering window. Thus if it is hidden by another window, you will capture the other window. This limitation is due to the heavy use of the hardware graphics system.
在大多数系统里,它的工作方式类似于一种对渲染窗口的screenshot截屏。如果它被其他窗口遮盖了,则会捕捉到其他窗口。这就限制了在硬件图像系统的大量使用。(hardware graphics system,我不知道怎么翻译)

翻译可能有问题

This function can be useful for integrating 3D plotting with Mayavi in a 2D plot created by matplotlib.
这个函数对3D图像转化为2D图像将会很有用。

一个例子

from mayavi import mlab
mlab.test_plot3d()
arr = mlab.screenshot()
import pylab as pl
pl.imshow(arr)
pl.axis('off')
pl.show()

.
.

sync_camera

mayavi.mlab.sync_camera(reference_figure, target_figure)
Synchronise the camera of the target_figure on the camera of the reference_figure.
这个没有多讲,回头再补充。
.
.

2 补充

1.关于engine的问题

先放两篇文章
http://docs.enthought.com/mayavi/mayavi/advanced_scripting.html
http://docs.enthought.com/mayavi/mayavi/auto/example_multiple_engines.html

这一章主要是一些图形图像控制,不涉及画的内容,画出来的图形生成渲染窗口,操作窗口的一些问题,比较常用的就是figure调整窗口,自动化处理比如保存为图像savefig,screenshot,还有,高级技巧,可以用mayavi的性能来做图像计算,以前提过一下,遇到了再写,这里留一个坑。

填坑区:
1.这一节有很多地方都没说清楚,回头来补充例子。
2.高级技巧,图形计算

更新(2018.12.12)
2018.12.11.——更新到screenshot
2018.12.12.——更完(都不好意思说更完,这周末来把中间坑坑洼洼的洞填一下。)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值