简体   繁体   English

从 python numpy ZA3CBC3F9D0CE2F2C1554E1B671D71D9 到 VTK 的 Sherical plot

[英]Sherical plot in VTK from python numpy arrays

I need to plot data that is living in Python (or some file that I read from python) and not living in a VTK file.我需要 plot 数据存在于 Python (或我从 python 读取的某些文件)中,而不是存在于 VTK 文件中。 I would like to achieve the equivalent of this simple matplotlib script using VTK with vectorized input (preferably numpy arrays).我想使用带有矢量化输入的 VTK(最好是 numpy 数组)来实现这个简单的 matplotlib 脚本的等效项。 I would like to be able to update this directly from the application in a responsive manner (ie the pattern changing in response to some parameter on the UI)我希望能够以响应方式直接从应用程序更新它(即响应 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()

在此处输入图像描述

I have found plenty of examples showing how to get data out of VTK structures into Python, but my requirement is the other way around.我发现了很多例子,展示了如何从 VTK 结构中获取数据到 Python,但我的要求是相反的。 I have also found examples of how to build up VTK arrays element by element, but this is Python;我还找到了如何逐个元素地构建 VTK arrays 的示例,但这是 Python; I need it vectorized as I want it to be updated responsively.我需要它矢量化,因为我希望它能够响应更新。 I also haven't been able to figure out how to get from a 2D StructuredGrid to a spherical plot.我也无法弄清楚如何从 2D StructuredGrid 到球形 plot。

Maybe this example can help:也许这个例子可以帮助:

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)

在此处输入图像描述

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

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