Created
October 15, 2024 19:10
-
-
Save fomightez/b4c116236dcbb5da5566ee318eda4915 to your computer and use it in GitHub Desktop.
PyVista screenshot stuff for SO 79089061
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "id": "f054b4d1-4515-4d86-828e-e295b86dd753", | |
| "metadata": {}, | |
| "source": [ | |
| "### Screenshots with PyVista\n", | |
| "\n", | |
| "Looking into https://stackoverflow.com/q/79089061/8508004\n", | |
| "\n", | |
| "Resources used:\n", | |
| "https://docs.pyvista.org/examples/02-plot/screenshot.html (or more specifically, https://docs.pyvista.org/_downloads/b6a7b8f0bc1eb3a8a254077499b41ad1/screenshot.py which came up when I searched 'pyvista screenshot' in Google)\n", | |
| "\n", | |
| "---------" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "id": "f442ef04-a2ef-4ad0-8a05-0ae64c8dd6e8", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "# from https://docs.pyvista.org/_downloads/b6a7b8f0bc1eb3a8a254077499b41ad1/screenshot.py\n", | |
| "\n", | |
| "import pyvista as pv\n", | |
| "from pyvista import examples\n", | |
| "\n", | |
| "# Get a sample file\n", | |
| "filename = examples.planefile\n", | |
| "mesh = pv.read(filename)\n", | |
| "\n", | |
| "\n", | |
| "# %%\n", | |
| "# You can also take a screenshot without creating an interactive plot window\n", | |
| "# using the :class:`pyvista.Plotter`:\n", | |
| "\n", | |
| "plotter = pv.Plotter(off_screen=True)\n", | |
| "plotter.add_mesh(mesh, color=\"orange\")\n", | |
| "plotter.show(screenshot='airplane.png')" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "id": "8d2102ca-a501-478d-ac59-3b02c86c77db", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "# adapted from https://docs.pyvista.org/_downloads/b6a7b8f0bc1eb3a8a254077499b41ad1/screenshot.py with OP code & https://docs.pyvista.org/api/examples/_autosummary/pyvista.examples.downloads.download_bunny.html and https://docs.pyvista.org/examples/00-load/read-file#read-file-example\n", | |
| "\n", | |
| "import pyvista as pv\n", | |
| "from pyvista import examples\n", | |
| "\n", | |
| "# Get a sample file\n", | |
| "dataset = examples.download_bunny()\n", | |
| "mesh = examples.download_bunny_coarse()\n", | |
| "\n", | |
| "\n", | |
| "# %%\n", | |
| "# You can also take a screenshot without creating an interactive plot window\n", | |
| "# using the :class:`pyvista.Plotter`:\n", | |
| "\n", | |
| "plotter = pv.Plotter(off_screen=True)\n", | |
| "plotter.add_mesh(mesh, color=\"orange\")\n", | |
| "plotter.show(screenshot='bunny_coarse.png')" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "id": "5ae41bf4-619e-4259-8ff5-dcd5cae4f755", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "# adapted from https://docs.pyvista.org/_downloads/b6a7b8f0bc1eb3a8a254077499b41ad1/screenshot.py with OP code & https://docs.pyvista.org/api/examples/_autosummary/pyvista.examples.downloads.download_bunny.html\n", | |
| "\n", | |
| "import pyvista as pv\n", | |
| "from pyvista import examples\n", | |
| "\n", | |
| "# Get a sample file\n", | |
| "dataset = examples.download_bunny()\n", | |
| "mesh = examples.download_bunny()\n", | |
| "\n", | |
| "\n", | |
| "# %%\n", | |
| "# You can also take a screenshot without creating an interactive plot window\n", | |
| "# using the :class:`pyvista.Plotter`:\n", | |
| "\n", | |
| "plotter = pv.Plotter(off_screen=True)\n", | |
| "plotter.add_mesh(mesh, color=\"orange\")\n", | |
| "plotter.show(screenshot='bunny.png')" | |
| ] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Python 3 (ipykernel)", | |
| "language": "python", | |
| "name": "python3" | |
| }, | |
| "language_info": { | |
| "codemirror_mode": { | |
| "name": "ipython", | |
| "version": 3 | |
| }, | |
| "file_extension": ".py", | |
| "mimetype": "text/x-python", | |
| "name": "python", | |
| "nbconvert_exporter": "python", | |
| "pygments_lexer": "ipython3", | |
| "version": "3.10.11" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 5 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment