1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
"""
Multi-Window Plot
~~~~~~~~~~~~~~~~~
Subplotting: having multiple scenes in a single window
"""
from __future__ import annotations
import pyvista as pv
from pyvista import examples
# sphinx_gallery_start_ignore
# labels are not supported in vtk-js
PYVISTA_GALLERY_FORCE_STATIC_IN_DOCUMENT = True
# sphinx_gallery_end_ignore
# %%
# This example shows how to create a multi-window plotter by specifying the
# ``shape`` parameter. The window generated is a two by two window by setting
# ``shape=(2, 2)``. Use the :func:`pyvista.Plotter.subplot` method to
# select the subplot you wish to be the active subplot.
plotter = pv.Plotter(shape=(2, 2))
plotter.subplot(0, 0)
plotter.add_text("Render Window 0", font_size=30)
globe = examples.load_globe()
texture = examples.load_globe_texture()
plotter.add_mesh(globe, texture=texture)
plotter.subplot(0, 1)
plotter.add_text("Render Window 1", font_size=30)
plotter.add_mesh(pv.Cube(), show_edges=True, color='lightblue')
plotter.subplot(1, 0)
plotter.add_text("Render Window 2", font_size=30)
sphere = pv.Sphere()
plotter.add_mesh(sphere, scalars=sphere.points[:, 2])
plotter.add_scalar_bar("Z")
# plotter.add_axes()
plotter.add_axes(interactive=True)
plotter.subplot(1, 1)
plotter.add_text("Render Window 3", font_size=30)
plotter.add_mesh(pv.Cone(), color="g", show_edges=True)
plotter.show_bounds(all_edges=True)
# Display the window
plotter.show()
# %%
plotter = pv.Plotter(shape=(1, 2))
# Note that the (0, 0) location is active by default
# load and plot an airplane on the left half of the screen
plotter.add_text("Airplane Example\n", font_size=30)
plotter.add_mesh(examples.load_airplane(), show_edges=False)
# load and plot the uniform data example on the right-hand side
plotter.subplot(0, 1)
plotter.add_text("Uniform Data Example\n", font_size=30)
plotter.add_mesh(examples.load_uniform(), show_edges=True)
# Display the window
plotter.show()
# %%
# Split the rendering window in half and subdivide it in a nr. of vertical or
# horizontal subplots.
# This defines the position of the vertical/horizontal splitting, in this
# case 40% of the vertical/horizontal dimension of the window
pv.global_theme.multi_rendering_splitting_position = 0.40
# shape="3|1" means 3 plots on the left and 1 on the right,
# shape="4/2" means 4 plots on top of 2 at bottom.
plotter = pv.Plotter(shape='3|1', window_size=(1000, 1200))
plotter.subplot(0)
plotter.add_text("Airplane Example")
plotter.add_mesh(examples.load_airplane(), show_edges=False)
# load and plot the uniform data example on the right-hand side
plotter.subplot(1)
plotter.add_text("Uniform Data Example")
plotter.add_mesh(examples.load_uniform(), show_edges=True)
plotter.subplot(2)
plotter.add_text("A Sphere")
plotter.add_mesh(pv.Sphere(), show_edges=True)
plotter.subplot(3)
plotter.add_text("A Cone")
plotter.add_mesh(pv.Cone(), show_edges=True)
# Display the window
plotter.show()
# %%
# To get full flexibility over the layout grid, you can define the relative
# weighting of rows and columns and register groups that can span over multiple
# rows and columns. A group is defined through a tuple ``(rows,cols)`` of row
# and column indices or slices. The group always spans from the smallest to the
# largest (row or column) id that is passed through the list or slice.
# numpy is imported for a more convenient slice notation through np.s_
import numpy as np
shape = (5, 4) # 5 by 4 grid
# First row is half the size and fourth row is double the size of the other rows
row_weights = [0.5, 1, 1, 2, 1]
# Third column is half the size and fourth column is double size of the other columns
col_weights = [1, 1, 0.5, 2]
groups = [
(0, np.s_[:]), # First group spans over all columns of the first row (0)
([1, 3], 0), # Second group spans over row 1-3 of the first column (0)
(np.s_[2:], [1, 2]), # Third group spans over rows 2-4 and columns 1-2
(slice(1, -1), 3), # Fourth group spans over rows 1-3 of the last column (3)
]
plotter = pv.Plotter(shape=shape, row_weights=row_weights, col_weights=col_weights, groups=groups)
# A grouped subplot can be activated through any of its composing cells using
# the subplot() method.
# Access all subplots and groups and plot something:
plotter.subplot(0, 0)
plotter.add_text("Group 1")
plotter.add_mesh(pv.Cylinder(direction=[0, 1, 0], height=20))
plotter.view_yz()
plotter.camera.zoom(10)
plotter.subplot(2, 0)
plotter.add_text("Group 2")
plotter.add_mesh(pv.ParametricCatalanMinimal(), show_edges=False, color='lightblue')
plotter.view_isometric()
plotter.camera.zoom(2)
plotter.subplot(2, 1)
plotter.add_text("Group 3")
plotter.add_mesh(examples.load_uniform(), show_edges=True)
plotter.subplot(1, 3)
plotter.add_text("Group 4")
globe = examples.load_globe()
texture = examples.load_globe_texture()
plotter.add_mesh(globe, texture=texture)
plotter.subplot(1, 1)
plotter.add_text("Cell (1,1)")
sphere = pv.Sphere()
plotter.add_mesh(sphere, scalars=sphere.points[:, 2])
plotter.add_scalar_bar("Z")
plotter.add_axes(interactive=True)
plotter.subplot(1, 2)
plotter.add_text("Cell (1,2)")
plotter.add_mesh(pv.Cone(), show_edges=True)
plotter.subplot(4, 0)
plotter.add_text("Cell (4,0)")
plotter.add_mesh(examples.load_airplane(), show_edges=False)
plotter.subplot(4, 3)
plotter.add_text("Cell (4,3)")
plotter.add_mesh(pv.Cube(), show_edges=True, color='lightblue')
# Display the window
plotter.show()
|