Writing VTK file using Python

To write VTK file using Python, download pytvtk. You can read the examples folder to get to know how to use it.

For example to write a structured points of scalar data stored in variable named Coef, we write:


vtk=VtkData(StructuredPoints([Nx,Ny,Nz]),\
PointData(Scalars(ravel(Coef,order='F'),'my scalar')))
vtk.tofile('myfile')

this will save to a file name myfile.vtk



Problem saving image in paraview 3.6.2 “Error: GLXBadContext 154”

I installed the binary paraview 3.6.2 in Kubuntu Hardy, but whenever I wanted to save image or animation, I got this error “Error: GLXBadContext 154”, this is the screenshot of the error message and the result of the saved image:

To resolve this problem:

  1. Go to “Edit” -> “Settings”
  2. click tab “Render View”-> “General”
  3. Uncheck the option “use offscreen rendering for screenshots”.
  4. Click OK.

After I did this, I can save the image savely. This is the example of the correct image:

Saving scalar finite element data from Matlab to VTK

I found this link to save scalar and vector data from Matlab to unstructured grid in VTK legacy format:
http://people.sc.fsu.edu/~burkardt/m_src/twod_to_vtk/twod_to_vtk.html

However, I need only the scalar part, so I modified accordingly. You can download my code here:
Download