I want to make a multi-window plot of varies scalars of 3D mesh and update it with new values.
Ques. 1 (resolved by setting key copy_mesh
)
However, when I am plotting multiple scalars with a same mesh in one window, a similar problem (subplots are sharing the colorlevels) to Ref happened (fig 1 and 2 with same mesh) .
I tried to reload the mesh , it goes right (fig 1 and 3).
Any idea what I am missing here would be greatly appreciated!
This are the code and image:
import pyvista as pv
from pyvista import examples
from pyvistaqt import BackgroundPlotter
shape = (3, 1)
plotter = BackgroundPlotter(shape=shape) # qt
# plotter = pv.Plotter()
plotter.subplot(0, 0)
sphere = pv.Sphere()
plotter.add_mesh(sphere, scalars=10*sphere.points[:, 2],scalar_bar_args={'title':'V1'})
plotter.subplot(1, 0)
plotter.add_mesh(sphere, scalars=sphere.points[:, 2],scalar_bar_args={'title':'V2'})
plotter.subplot(2, 0)
sphere = pv.Sphere() # if reload sphere it goes well
plotter.add_mesh(sphere, scalars=sphere.points[:, 2],scalar_bar_args={'title':'V3'})
# Display the window without qt
plotter.show() # break point
Ques. 2 (resolved by save plotter.mesh
)
Additionally, I tried to update each subplot (from fig1 to fig3) by various data. However, only the last one (fig3) can be updated by update_scalars
. The fig1 unchanged evenif subplot(0,0)
is used.
# it works
plotter.update_scalars(sphere.points[:,2]*5)
# it does not work to fig1 but work to fig3
plotter.subplot(0,0)
plotter.update_scalars(sphere.points[:,2]*5)
I note update_scalars()
default update latest mesh
if multi meshes exist
def update_scalars(self, scalars, mesh=None, render=True):
mesh : vtk.PolyData or vtk.UnstructuredGrid, optional
Object that has already been added to the Plotter. If
None, uses last added mesh.