You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

非结构化数据集3D场线可视化求助:PyVista与Plotly实现遇阻

非完整规则网格矢量场3D流场可视化故障排查

我尝试用PyVista Streamlines和Plotly可视化非完整规则网格矢量场的场线,但均未成功:

  • Plotly:在浏览器中打开后无管道显示,且轴值错误
  • PyVista:虽然有显示,但流场方向错误,与预期的绕中心锥的纵向流场不符

不过我用其他工具绘制的2D流场图效果良好,数据可获取。

import pandas as pd
import numpy as np
import pyvista as pv
import plotly.graph_objects as go

df = pd.read_csv("mix_griddata.csv")

X = df['X']
Y = df['Y']
Z = df['Z']
Vx = df['Vx']
Vy = df['Vy']
Vz = df['Vz']


fig = go.Figure(data=go.Streamtube(
    x = X,
    y = Y,
    z = Z,
    u = Vx,
    v = Vy,
    w = Vz,
    starts = dict(
        x = X.sample(frac=0.01,replace=False),
        y = Y.sample(frac=0.01,replace=False),
        z = Z.sample(frac=0.01,replace=False)
    ),
    sizeref =1,
    colorscale = 'Portland',
    showscale = False,
    maxdisplayed = 30000000
))

fig.update_layout(
    scene = dict(
        aspectratio = dict(
            x = 1,
            y = 1,
            z = 1
        )
    ),
    margin = dict(
        t = 10,
        b = 10,
        l = 10,
        r = 10
    )
)

fig.show(renderer="browser")


#Streamlines

mix_FD_grid = np.load("C:/Users/hd377/OneDrive - ensam.eu/0-Thesis/Fibres_Direction_in_allvolume/mix/mix_FD_grid.npy")

origin = (0,0,0)
mesh = pv.UniformGrid(dimensions=mix_FD_grid[:,:,:,0].shape, spacing=(1, 1, 1), origin=origin)
vectors = np.empty((mesh.n_points, 3))
vectors[:, 0] = mix_FD_grid[:,:,:,0].flatten()
vectors[:, 1] = mix_FD_grid[:,:,:,1].flatten()
vectors[:, 2] = mix_FD_grid[:,:,:,2].flatten()

mesh['vectors'] = vectors

stream, src = mesh.streamlines(
    'vectors', return_source=True, max_steps = 20000, n_points=200, source_radius=25, source_center=(15, 0, 30)
)

p = pv.Plotter()
p.add_mesh(mesh.outline(), color="k")
p.add_mesh(stream.tube(radius=0.1))
p.camera_position = [(182.0, 177.0, 50), (139, 105, 19), (-0.2, -0.2, 1)]
p.show() 

内容的提问来源于stack exchange,提问作者Hélène Penvern

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 18:15:59