Mayavi学习之旅——基础知识及学习资源

导读:本篇文章讲解 Mayavi学习之旅——基础知识及学习资源,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com

介绍

Mayavi是一款3D科学数据可视化Python库,其简单易用,可视化功能非常强大,能够满足我们对各种数据的可视化需求。
在这里插入图片描述

学习资源

官网:https://docs.enthought.com/mayavi/mayavi/
mlab模块参考手册:https://docs.enthought.com/mayavi/mayavi/auto/mlab_reference.html#mlab-reference

https://wizardforcel.gitbooks.io/hyry-studio-scipy/content/9.html

安装

可以使用pip直接进行安装:

pip install PyQt5 vtk
pip install mayavi

我曾经成功的版本:

pip install PyQt5==5.15.2 vtk==8.1.0
pip install mayavi==4.7.1

这种安装讲道理是官方推荐的安装方法,但是容易出现以下问题:

Building wheel for mayavi (setup.py) ... error
Running setup.py install for mayavi ... error

此时可以采用源码安装方案:

git clone https://github.com/enthought/mayavi.git
cd mayavi
pip install -r requirements.txt
pip install PyQt5
python setup.py install

验证安装:
终端直接执行mayavi2,出现如下界面则说明安装成功:
在这里插入图片描述

mayavi.mlab为脚本中绘图包:
https://docs.enthought.com/mayavi/mayavi/mlab.html#simple-scripting-with-mlab
所有函数索引为:
https://docs.enthought.com/mayavi/mayavi/auto/mlab_reference.html#mlab-reference

import numpy as np
import mayavi.mlab as mlab
try:
    raw_input  # Python 2
except NameError:
    raw_input = input  # Python 3

fig = mlab.figure(
            figure=None, bgcolor=(0, 0, 0), fgcolor=None, engine=None, size=(1000, 500))

fov = np.array(
        [[20.0, 20.0, 0.0, 0.0], [20.0, -20.0, 0.0, 0.0]], dtype=np.float64  # 45 degree
    )

def load_velo_scan(velo_filename, dtype=np.float32, n_vec=4):
    scan = np.fromfile(velo_filename, dtype=dtype)
    scan = scan.reshape((-1, n_vec))
    return scan

pc = load_velo_scan('/media/zhanghm/Data/Datasets/KITTI/tracking/training/velodyne/0019/000000.bin')
print(pc.shape)

s = np.full((pc.shape[0], ), 2)
mlab.points3d(
        pc[:, 0],
        pc[:, 1],
        pc[:, 2],
        mode='point',
        color=(1,0,1),
        #colormap="gnuplot",
        colormap="copper",
        scale_factor=10,
        figure=fig)
input_str = raw_input()
mlab.points3d(
        pc[:, 0],
        pc[:, 1],
        pc[:, 2],
        color=(1,0,1),
        colormap="gnuplot",
        scale_factor=0.01,
        figure=fig)

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/121194.html

(0)
seven_的头像seven_bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!