{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Contouring\n\nGenerate iso-lines or -surfaces for the scalars of a surface or volume.\n\n3D meshes can have 2D iso-surfaces of a scalar field extracted and 2D\nsurface meshes can have 1D iso-lines of a scalar field extracted.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import pyvista as pv\nfrom pyvista import examples" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Iso-Lines\n\nLet\\'s extract 1D iso-lines of a scalar field from a 2D surface mesh.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "mesh = examples.load_random_hills()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "help(mesh.contour)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "contours = ..." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "pl = pv.Plotter()\npl.add_mesh(mesh, opacity=0.85)\npl.add_mesh(contours, color=\"white\", line_width=5)\npl.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Iso-Surfaces\n\nLet\\'s extract 2D iso-surfaces of a scalar field from a 3D mesh.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "mesh = examples.download_embryo()\nmesh" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For this example dataset, let\\'s create 5 contour levels between the\nvalues of 50 and 200\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "contours = ..." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "pl = pv.Plotter()\npl.add_mesh(mesh.outline(), color=\"k\")\npl.add_mesh(contours, opacity=0.25, clim=[0, 200])\npl.camera_position = [\n (-130.99381142132086, 644.4868354828589, 163.80447435848686),\n (125.21748748157661, 123.94368717158413, 108.83283586619626),\n (0.2780372840777734, 0.03547871361794171, 0.9599148553609699),\n]\npl.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```{=html}\n<center>\n <a target=\"_blank\" href=\"https://colab.research.google.com/github/pyvista/pyvista-tutorial/blob/gh-pages/notebooks/tutorial/04_filters/exercises/d_contouring.ipynb\">\n <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/ width=\"150px\">\n </a>\n</center>\n```\n" ] } ], "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.11" } }, "nbformat": 4, "nbformat_minor": 0 }