Debian Codegraph @

examples/02-plot/multi_window.py

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