{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Multi-Window Plot\n\nSubplotting: having multiple scenes in a single window\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": [ "This example shows how to create a multi-window plotter by specifying\nthe `shape` parameter. The window generated is a two by two window by\nsetting `shape=(2, 2)`. Use the\n`pyvista.Plotter.subplot`{.interpreted-text role=\"func\"} method to\nselect the subplot you wish to be the active subplot.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "plotter = pv.Plotter(shape=(2, 2))\n\nplotter.subplot(0, 0)\nplotter.add_text(\"Render Window 0\", font_size=30)\nglobe = examples.load_globe()\ntexture = examples.load_globe_texture()\nplotter.add_mesh(globe, texture=texture)\n\nplotter.subplot(0, 1)\nplotter.add_text(\"Render Window 1\", font_size=30)\nplotter.add_mesh(pv.Cube(), show_edges=True, color='lightblue')\n\nplotter.subplot(1, 0)\nplotter.add_text(\"Render Window 2\", font_size=30)\nsphere = pv.Sphere()\nplotter.add_mesh(sphere, scalars=sphere.points[:, 2])\nplotter.add_scalar_bar(\"Z\")\n# plotter.add_axes()\nplotter.add_axes(interactive=True)\n\nplotter.subplot(1, 1)\nplotter.add_text(\"Render Window 3\", font_size=30)\nplotter.add_mesh(pv.Cone(), color=\"g\", show_edges=True)\nplotter.show_bounds(all_edges=True)\n\n# Display the window\nplotter.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "plotter = pv.Plotter(shape=(1, 2))\n\n# Note that the (0, 0) location is active by default\n# load and plot an airplane on the left half of the screen\nplotter.add_text(\"Airplane Example\\n\", font_size=30)\nplotter.add_mesh(examples.load_airplane(), show_edges=False)\n\n# load and plot the uniform data example on the right-hand side\nplotter.subplot(0, 1)\nplotter.add_text(\"Uniform Data Example\\n\", font_size=30)\nplotter.add_mesh(examples.load_uniform(), show_edges=True)\n\n# Display the window\nplotter.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Split the rendering window in half and subdivide it in a nr. of vertical\nor horizontal subplots.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# This defines the position of the vertical/horizontal splitting, in this\n# case 40% of the vertical/horizontal dimension of the window\npv.global_theme.multi_rendering_splitting_position = 0.40\n\n# shape=\"3|1\" means 3 plots on the left and 1 on the right,\n# shape=\"4/2\" means 4 plots on top of 2 at bottom.\nplotter = pv.Plotter(shape='3|1', window_size=(1000, 1200))\n\nplotter.subplot(0)\nplotter.add_text(\"Airplane Example\")\nplotter.add_mesh(examples.load_airplane(), show_edges=False)\n\n# load and plot the uniform data example on the right-hand side\nplotter.subplot(1)\nplotter.add_text(\"Uniform Data Example\")\nplotter.add_mesh(examples.load_uniform(), show_edges=True)\n\nplotter.subplot(2)\nplotter.add_text(\"A Sphere\")\nplotter.add_mesh(pv.Sphere(), show_edges=True)\n\nplotter.subplot(3)\nplotter.add_text(\"A Cone\")\nplotter.add_mesh(pv.Cone(), show_edges=True)\n\n# Display the window\nplotter.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To get full flexibility over the layout grid, you can define the\nrelative weighting of rows and columns and register groups that can span\nover multiple rows and columns. A group is defined through a tuple\n`(rows,cols)` of row and column indices or slices. The group always\nspans from the smallest to the largest (row or column) id that is passed\nthrough the list or slice.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# numpy is imported for a more convenient slice notation through np.s_\nimport numpy as np\n\nshape = (5, 4) # 5 by 4 grid\n# First row is half the size and fourth row is double the size of the other rows\nrow_weights = [0.5, 1, 1, 2, 1]\n# Third column is half the size and fourth column is double size of the other columns\ncol_weights = [1, 1, 0.5, 2]\ngroups = [\n (0, np.s_[:]), # First group spans over all columns of the first row (0)\n ([1, 3], 0), # Second group spans over row 1-3 of the first column (0)\n (np.s_[2:], [1, 2]), # Third group spans over rows 2-4 and columns 1-2\n (slice(1, -1), 3), # Fourth group spans over rows 1-3 of the last column (3)\n]\n\nplotter = pv.Plotter(shape=shape, row_weights=row_weights, col_weights=col_weights, groups=groups)\n\n# A grouped subplot can be activated through any of its composing cells using\n# the subplot() method.\n\n# Access all subplots and groups and plot something:\nplotter.subplot(0, 0)\nplotter.add_text(\"Group 1\")\nplotter.add_mesh(pv.Cylinder(direction=[0, 1, 0], height=20))\nplotter.view_yz()\nplotter.camera.zoom(10)\n\nplotter.subplot(2, 0)\nplotter.add_text(\"Group 2\")\nplotter.add_mesh(pv.ParametricCatalanMinimal(), show_edges=False, color='lightblue')\nplotter.view_isometric()\nplotter.camera.zoom(2)\n\nplotter.subplot(2, 1)\nplotter.add_text(\"Group 3\")\nplotter.add_mesh(examples.load_uniform(), show_edges=True)\n\nplotter.subplot(1, 3)\nplotter.add_text(\"Group 4\")\nglobe = examples.load_globe()\ntexture = examples.load_globe_texture()\nplotter.add_mesh(globe, texture=texture)\n\nplotter.subplot(1, 1)\nplotter.add_text(\"Cell (1,1)\")\nsphere = pv.Sphere()\nplotter.add_mesh(sphere, scalars=sphere.points[:, 2])\nplotter.add_scalar_bar(\"Z\")\nplotter.add_axes(interactive=True)\n\nplotter.subplot(1, 2)\nplotter.add_text(\"Cell (1,2)\")\nplotter.add_mesh(pv.Cone(), show_edges=True)\n\nplotter.subplot(4, 0)\nplotter.add_text(\"Cell (4,0)\")\nplotter.add_mesh(examples.load_airplane(), show_edges=False)\n\nplotter.subplot(4, 3)\nplotter.add_text(\"Cell (4,3)\")\nplotter.add_mesh(pv.Cube(), show_edges=True, color='lightblue')\n\n# Display the window\nplotter.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 }