简体   繁体   English

替代 Mayavi 进行科学 3d 绘图

[英]Alternative to Mayavi for scientific 3d plotting

I need to plot a scalar field that is structured in a 3D grid as the one that follows:我需要绘制一个在3D 网格中构造的标量场,如下所示:

import numpy as np
from mayavi import mlab

dt = 10
X,Y,Z = np.mgrid[0:dt,0:dt,0:dt]

F = X**2+Y**2+Z**2

test = mlab.figure(size = (1024,768), bgcolor = (1,1,1), fgcolor = (0, 0, 0))
sf = mlab.pipeline.scalar_field(X,Y,Z,F)
vl = mlab.pipeline.volume(sf)
mlab.outline()
mlab.axes()
mlab.title('Can not change font size for this title')
mlab.xlabel('Only end ticks')
mlab.ylabel('No major ticks')

在此处输入图片说明

I would like to do so in Python since I simulate many datasets in this language and I would like to be able to visualize them quickly as I perform sensitivities in my simulation parameters.我想在 Python 中这样做,因为我用这种语言模拟了许多数据集,并且当我在模拟参数中执行敏感性时,我希望能够快速可视化它们。

Mayavi seemed to offer pretty standard routines for scientific 3d plotting. Mayavi 似乎为科学 3d 绘图提供了非常标准的例程。 However, when it comes to communicate these plots in publications, very basic plot customizations are not available such as major and minor ticks in the axes.然而,当谈到在出版物中传达这些图时,非常基本的图定制不可用,例如轴上的主要和次要刻度。 Also, those very basic features that are supported do not even work properly to date (eg see example in font size bug and here ).此外,支持的那些非常基本的功能迄今为止甚至无法正常工作(例如,请参见字体大小错误此处的示例)。

Is there any decent and easy to use scientific 3D plotting library in Python? Python 中是否有任何体面且易于使用的科学3D绘图库? I have tried learning vtk but the website examples seem to be obsolete (eg volume rendering example that fails to run, I tried editing many lines of code to make it work without luck) and others seem to agree that the documentation is lacking.我曾尝试学习 vtk,但网站示例似乎已过时(例如,无法运行的体积渲染示例,我尝试编辑多行代码以使其在没有运气的情况下正常工作),而其他人似乎同意缺少文档。

By decent scientific plotting library I mean the following:通过体面的科学绘图库,我的意思是:

  • Allows for customizing fonts in axes, labels, titles, etc.允许自定义轴、标签、标题等中的字体。
  • Can edit axes ticks spacing (with major ticks at the very least).可以编辑轴刻度间距(至少有主要刻度)。
  • Can add colorbars可以添加颜色条
  • Has documentation.有文档。

You should try matplotlib, if you haven't done so already.你应该尝试 matplotlib,如果你还没有这样做的话。 It's not difficult to use meshgrid and contour or contourf (you'll find scripts on the web easily enough) to plot data on structured grids.使用meshgridcontourcontourf (你会很容易在网上找到脚本)在结构化网格上绘制数据并不困难。 It's even possible to plot on unstructured grids (Check this out: https://grantingram.wordpress.com/plotting-2d-unstructured-data-using-free-software/ )甚至可以在非结构化网格上绘图(请查看: https : //grantingram.wordpress.com/plotting-2d-unstructured-data-using-free-software/

It has your characteristics of a "decent" scientific plotting library.它具有“体面”科学绘图库的特点。

EDIT: When you say '3D' plotting, I assumed you wanted a plot of a function of 2 variables, so that its graph is 3D.编辑:当你说“3D”绘图时,我假设你想要一个 2 个变量的函数图,所以它的图是 3D 的。

If, however, you have data depending on 3 space variables, I assume you want the ability to display cut planes and such.但是,如果您的数据取决于 3 个空间变量,我假设您希望能够显示剖切面等。 Then I recommend you output your data to files and use a proper visualization package such as ParaView (which uses VTK) or TecPlot (non-free).然后我建议您将数据输出到文件并使用适当的可视化包,例如 ParaView(使用 VTK)或 TecPlot(非免费)。 You can automate the visualization pipeline through scripting (I believe ParaView supports Python scripting).您可以通过脚本自动化可视化管道(我相信 ParaView 支持 Python 脚本)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM