I'd like to visualize scalar data located on the nodes of a quad mesh (2D) using VTK in Python3. The closest example I've found is vtk quad mesh, but it only seems to visualize the mesh, not data on the mesh. Could someone point me to a better example?
As mentioned by @AloneProgrammer in the comments, you could use ParaView since it is effortless. As added by @WolfgangBangerth, you could also try VisIt that provides a frontend for VTK algorithms.
If you need to do it programmatically through Python scripts you could use:
Here's a simple working example of what I wanted to do, using PyVista. It needs X11 to plot. So, if you are running on a system without X11 (e.g. Ubuntu under WSL2) you might need to install Xvfb. See here for further instructions.
This example is based on this PyVista example
import numpy as np import pyvista as pv # mesh points vertices = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [2, 0, 0], [3, 1, 0]]) # mesh faces # the 4 indicates how many nodes are present # other numbers are indicies in the vertices array faces = np.hstack([[4, 0, 1, 2, 3], [4, 1, 4, 5, 2]]) # define a surface or as PyVista calls it a 'mesh' object surf = pv.PolyData(vertices, faces) # define nodal/point data surf.point_arrays['point1'] = np.arange(surf.n_points) # define cell/element data surf.cell_arrays['cell1'] = np.arange(surf.n_cells) # parameters for the colorbar sargs = dict(height=0.25, vertical=True, position_x=0.85, position_y=0.05) # create the plotter p = pv.Plotter() # show the axes widget p.show_axes() # add the mesh to the plotter and tell it which field to display # and set the arguments for the scalar bar p.add_mesh(surf,scalars='point1',scalar_bar_args=sargs) # specify the view p.view_xy() # plot and take a screenshot p.show(screenshot='pyvistatest.png')