Python EVTK Library

1.6.0 · active · verified Fri Apr 17

pyevtk is a Python library for exporting numerical data (like structured grids, unstructured grids, and points) into binary VTK (Visualization Toolkit) files, enabling visualization in tools like ParaView or VisIt. As of version 1.6.0, it supports various data types and has an active, albeit slow, release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to export a structured grid with both cell-centered and point-centered data to a VTK Structured Grid (.vts) file using `gridToVTK`.

import numpy as np
from pyevtk.hl import gridToVTK

# Define grid dimensions
nx, ny, nz = 64, 64, 64

# Coordinates
x = np.arange(0, nx, 1, dtype='float64')
y = np.arange(0, ny, 1, dtype='float64')
z = np.arange(0, nz, 1, dtype='float64')

# Cell data (e.g., temperature)
temp = np.random.rand(nx - 1, ny - 1, nz - 1)

# Point data (e.g., pressure)
press = np.random.rand(nx, ny, nz)

# Export to VTK file
gridToVTK(
    "output_grid",
    x, y, z,
    cellData={'temperature': temp},
    pointData={'pressure': press}
)

print("VTK file 'output_grid.vts' generated successfully.")

view raw JSON →