K3D-tools / K3D-jupyter

K3D lets you create 3D plots backed by WebGL with high-level API (surfaces, isosurfaces, voxels, mesh, cloud points, vtk objects, volume renderer, colormaps, etc). The primary aim of K3D-jupyter is to be easy for use as stand alone package like matplotlib, but also to allow interoperation with existing libraries as VTK.
MIT License
921 stars 123 forks source link

automate screenshot in script #315

Closed HumHongeKamyaab closed 2 years ago

HumHongeKamyaab commented 2 years ago

I want to save the figure as a PNG file in particular camera orientation. While we can set camera using plot.camera, I couldn't find something like plot.save, so that a png image can be saved using a python script, and we don't have to manually select screenshot from the widget to save the image,

artur-trzesiok commented 2 years ago

Hi @HumHongeKamyaab

For screenshots from jupyter notebook mode you can use plot.fetch_screenshot() like here

https://github.com/K3D-tools/K3D-jupyter/blob/main/examples/screenshot_generator.ipynb

For execution without jupyter we have headless rendering: https://github.com/K3D-tools/K3D-jupyter/blob/main/examples/headless.ipynb

Best regards, Artur

youssefassis commented 2 years ago

Hi @artur-trzesiok

Thanks for providing this veryuseful visualization library.

I have a problem when I try to take a single screenshot using the exact same code provided in the documentation here. After running this line of code:plt.fetch_screenshot() , the output of plt.screenshot is empty '' !! Do you please have any idea why it didn't work?

Best regards,

tgandor commented 2 years ago

Hi Youssef,

this is the old, non-headless screenshot mechanism. For the new mechanism see this example: https://github.com/K3D-tools/K3D-jupyter/blob/main/examples/headless.ipynb

For this example: https://github.com/K3D-tools/K3D-jupyter/blob/main/examples/screenshot_generator.ipynb you need a few things:

or use the generator approach further down in the example.

youssefassis commented 2 years ago

Thank you Tgandor, It works using the headless screenshot mechanism.