pyvista / pyvista-support

[moved] Please head over to the Discussions tab of the PyVista repository
https://github.com/pyvista/pyvista/discussions
60 stars 4 forks source link

`off_screen=True` not rendering anything in mesh plot #436

Open gewitterblitz opened 3 years ago

gewitterblitz commented 3 years ago

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)
Screen Shot 2021-06-07 at 7 12 58 PM

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')

my_image

Here's the output of pv.Report()

Screen Shot 2021-06-07 at 7 39 17 PM
gewitterblitz commented 3 years ago

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

Screen Shot 2021-06-07 at 8 11 16 PM

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

Screen Shot 2021-06-07 at 8 12 54 PM

However, for my data, even the external window generated using just p = pv.Plotter(notebook=False) does not show any isosurfaces:

Screen Shot 2021-06-07 at 8 18 47 PM
akaszynski commented 3 years ago

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