在VTK中用python的numpy数组绘制Sherical图。

问题描述 投票:0回答:1

我需要绘制活在Python中的数据(或从python中读取的一些文件),而不是活在VTK文件中。我想用VTK实现相当于这个简单的matplotlib脚本,并使用 矢量化 输入(最好是numpy数组)。我希望能够直接从应用程序中以响应的方式更新这些信息(即模式根据UI上的一些参数而改变)。

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# make some interesting data
theta = np.linspace(-np.pi/2, np.pi/2, 181)
phi = np.arange(np.pi, -np.pi, -np.pi/180)[::-1]
r = np.outer(np.sin(2*phi), np.sin(2*theta))

# xyz it
x = r * np.outer(np.cos(phi), np.sin(theta))
y = r * np.outer(np.sin(phi), np.sin(theta))
z = r * np.outer(np.ones(np.size(phi)), np.cos(theta))

# plot the surface
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(x, y, z, color='b')

plt.show()

enter image description here

我已经找到了很多例子来说明如何将数据从 VTK 结构中获取到 Python 中,但我的要求是反过来的,我也找到了如何逐个元素建立 VTK 数组的例子,但这是 Python;我需要将它矢量化,因为我希望它能响应更新。我也找到了如何逐个元素建立VTK数组的例子,但这是Python,我需要它的矢量化,因为我希望它能被响应地更新。我也没能弄清楚如何从一个二维结构化网格到一个球形图。

python visualization vtk
1个回答
1
投票

可能是 本例 可以帮助。

from vedo import *
from vedo.pyplot import plot
import numpy as np

def rhofunc(theta, phi):
    if theta < 0.2:
        return np.nan # make some points invalid
    return (3*cos(theta)**2 - 1)**2 # Y(l=2 m=0)

# Build the plot, return a vtkAssembly
spl = plot(rhofunc, mode='spheric', cmap='viridis')
show(spl, axes=12)

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.