pyvista-support
pyvista-support copied to clipboard
`off_screen=True` not rendering anything in mesh plot
Hi,
Pyvista newbie here. I am trying to plot an isosurface plot from a 3D uniform gird. I see the output when using panel backend in the jupyter notebook (using Jlab 3.x) but the isosurfaces disappear when using off_screen = True kwarg in pv.Plotter()
Output with panel:
import pyvista as pv
pv.set_jupyter_backend('panel')
tt = grid.ctp()
surf_2dB = tt.contour(isosurfaces=[2],scalars='zdr')
surf_3dB = tt.contour(isosurfaces=[3],scalars='zdr')
surf_4dB = tt.contour(isosurfaces=[4],scalars='zdr')
surf_5dB = tt.contour(isosurfaces=[5],scalars='zdr')
p = pv.Plotter(notebook=True)
p.add_mesh(tt.outline(), color="k")
p.add_mesh(surf_2dB,scalars='zdr',clim=[1,5], opacity="linear",cmap='pyart_NWSRef',
use_transparency=False,label='2dB',smooth_shading=True)
p.add_mesh(surf_3dB,scalars='zdr',clim=[1,5], opacity="linear",cmap='pyart_NWSRef',
use_transparency=False,label='3dB',smooth_shading=True)
p.add_mesh(surf_4dB,scalars='zdr',clim=[1,5], opacity="linear",cmap='pyart_NWSRef',
use_transparency=False,label='4dB',smooth_shading=True)
p.add_mesh(surf_5dB,scalars='zdr',clim=[1,5], opacity="linear",cmap='pyart_NWSRef',
use_transparency=False,label='5dB',smooth_shading=True)
p.add_bounding_box()
p.set_background("white", top="aliceblue")
p.update_scalar_bar_range([0,5])
p.add_legend()
p.add_title('ZDR KTLX')
p.set_background(color='white')
cpos = [(172354.13710915236, 343983.2042471954, 149394.6790957107),
(-14750.0, 60250.0, 70000.0),
(-0.13333266315583228, -0.18454825625010587, 0.9737373064902151)
]
p.show(cpos=cpos)
Output without panel:
import pyvista as pv
pv.set_plot_theme('document')
tt = grid.ctp()
surf_2dB = tt.contour(isosurfaces=[2],scalars='zdr')
surf_3dB = tt.contour(isosurfaces=[3],scalars='zdr')
surf_4dB = tt.contour(isosurfaces=[4],scalars='zdr')
surf_5dB = tt.contour(isosurfaces=[5],scalars='zdr')
p = pv.Plotter(notebook=False, off_screeen=True)
p.add_mesh(tt.outline(), color="k")
p.add_mesh(surf_2dB,scalars='zdr',clim=[1,5], opacity="linear",cmap='pyart_NWSRef',
use_transparency=False,label='2dB',smooth_shading=True)
p.add_mesh(surf_3dB,scalars='zdr',clim=[1,5], opacity="linear",cmap='pyart_NWSRef',
use_transparency=False,label='3dB',smooth_shading=True)
p.add_mesh(surf_4dB,scalars='zdr',clim=[1,5], opacity="linear",cmap='pyart_NWSRef',
use_transparency=False,label='4dB',smooth_shading=True)
p.add_mesh(surf_5dB,scalars='zdr',clim=[1,5], opacity="linear",cmap='pyart_NWSRef',
use_transparency=False,label='5dB',smooth_shading=True)
# p.set_scale(zscale=2) # doesn't work that well
p.add_bounding_box()
p.set_background("white", top="aliceblue")
p.update_scalar_bar_range([0,5])
p.add_legend()
p.add_title('ZDR KTLX')
p.set_background(color='white')
cpos = [(172354.13710915236, 343983.2042471954, 149394.6790957107),
(-14750.0, 60250.0, 70000.0),
(-0.13333266315583228, -0.18454825625010587, 0.9737373064902151)
]
p.show(cpos=cpos,screenshot='my_image.png')

Here's the output of pv.Report()
Per #175, the following code
#https://github.com/pyvista/pyvista-support/issues/175
import pyvista as pv
from pyvista import examples
# pv.rcParams['volume_mapper'] = 'fixed_point'
model = examples.download_damavand_volcano()
opacity = [0, 0.75, 0, 0.75, 1.0]
clim = [0, 100]
p = pv.Plotter(notebook=False)
p.add_volume(model, cmap="magma", clim=clim,
opacity=opacity, opacity_unit_distance=6000,)
p.show(screenshot='volcano.png',return_viewer=True)
creates an external window containing expected output

but fails to save any png file.
If I use p = pv.Plotter(notebook=False,off_screen=True) instead, I get an empty plot in volcano.png file
However, for my data, even the external window generated using just p = pv.Plotter(notebook=False) does not show any isosurfaces:
Using panel requires the intermediate translation to vtk.js, and this has a variety of issues (including failing to convert over a variety of VTK objects to the js world).
As for off_screen, this is likely to be a VTK issue and probably will have to be raised on their forms.
If you absolutely need to have off_screen plotting, you might try compiling vtk with EGL on Mac (though I've never compiled VTK on a Mac with EGL). See https://docs.pyvista.org/extras/building_vtk.html