Skip to content

Instantly share code, notes, and snippets.

@amolrajan
Forked from mrklein/plot_temperature.py
Created April 4, 2020 20:49
Show Gist options
  • Select an option

  • Save amolrajan/309d2b38d7e38fc39ce193a7399e40c1 to your computer and use it in GitHub Desktop.

Select an option

Save amolrajan/309d2b38d7e38fc39ce193a7399e40c1 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())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment