VTK 中文站
返回实战教程
集成实战 2026-05-19 1 分钟阅读

VTK + Matplotlib 数据可视化

把 VTK 数据数组导出到 NumPy,再使用 Matplotlib 绘制统计图或二维曲线。

使用场景

VTK 擅长三维空间数据和交互渲染,Matplotlib 擅长二维曲线、统计图和论文图。两者结合可以同时满足分析和展示。

数据导出

from vtk.util import numpy_support

vtk_array = polydata.GetPointData().GetArray("pressure")
values = numpy_support.vtk_to_numpy(vtk_array)

绘图

import matplotlib.pyplot as plt

plt.hist(values, bins=50)
plt.xlabel("pressure")
plt.ylabel("count")
plt.show()

建议

不要把 Matplotlib 当作三维交互渲染替代品。它更适合做统计、剖面线和结果报告。

反馈

发现内容错误、链接失效或希望补充案例,可以提交反馈。