Skip to content

Instantly share code, notes, and snippets.

@mrklein
Created September 19, 2017 08:52
Show Gist options
  • Save mrklein/0829ce12808dcb63c9b00dc5c3782131 to your computer and use it in GitHub Desktop.
Save mrklein/0829ce12808dcb63c9b00dc5c3782131 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ipython
# -*- coding: utf-8 -*-
import sys
import vtk
import numpy as np
import matplotlib.pyplot as plt
def _read_data(filename):
"""Read data from time, return tuple of arrays x, y, T."""
reader = vtk.vtkXMLImageDataReader()
reader.SetFileName(filename)
reader.Update()
data = reader.GetOutput()
temperature = data.GetPointData().GetArray(0)
n = data.GetNumberOfPoints()
x = np.zeros(n)
y = np.zeros(n)
T = np.zeros(n)
for i in range(n):
x[i] = data.GetPoint(i)[0]
y[i] = data.GetPoint(i)[1]
T[i] = temperature.GetValue(i)
return x, y, T
def _plot():
DATA_FILE = 'Case-1.vti'
x, y, T = _read_data(DATA_FILE)
plt.figure(figsize=(8, 8))
plt.jet()
plt.tricontourf(x, y, T, 64)
plt.savefig('temperature.pdf', bbox_inches='tight', bbox_padding=0.5)
if __name__ == '__main__':
sys.exit(_plot())
@mrklein
Copy link
Author

mrklein commented Sep 19, 2017

And result

temperature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment