{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Saving Screenshots\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n\nimport pyvista as pv\nfrom pyvista import examples\n\n# Get a sample file\nfilename = examples.planefile\nmesh = pv.read(filename)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can also take a screenshot without creating an interactive plot\nwindow using the `pyvista.Plotter`{.interpreted-text role=\"class\"}:\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "plotter = pv.Plotter(off_screen=True)\nplotter.add_mesh(mesh, color=\"orange\")\nplotter.show(screenshot='airplane.png')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `img` array can be used to plot the screenshot in `matplotlib`:\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "plt.imshow(plotter.image)\nplt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.12.2" } }, "nbformat": 4, "nbformat_minor": 0 }