File: linked_views.py

package info (click to toggle)
python-pyvista 0.46.4-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 176,968 kB
  • sloc: python: 94,346; sh: 216; makefile: 70
file content (54 lines) | stat: -rw-r--r-- 1,370 bytes parent folder | download
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
"""
.. _linked_views_example:

Linked Views in Subplots
~~~~~~~~~~~~~~~~~~~~~~~~

This example demonstrates how to create linked views in PyVista subplots
using :func:`~pyvista.Plotter.link_views`, where camera movements
in one view are synchronized with other views. This is particularly useful when comparing
different versions or representations of the same model.

"""

from __future__ import annotations

import numpy as np

import pyvista as pv
from pyvista import examples

pv.set_plot_theme('document')

# download mesh
mesh = examples.download_cow()

decimated = mesh.decimate_boundary(target_reduction=0.75)

p = pv.Plotter(shape=(1, 2), border=False)
p.subplot(0, 0)
p.add_text('Original mesh', font_size=24)
p.add_mesh(mesh, show_edges=True, color=True)
p.subplot(0, 1)
p.add_text('Decimated version', font_size=24)
p.add_mesh(decimated, color=True, show_edges=True)

p.link_views()  # link all the views
# Set a camera position to all linked views
p.camera_position = [(15, 5, 0), (0, 0, 0), (0, 1, 0)]

p.open_gif('linked.gif')
# Update camera and write a frame for each updated position
nframe = 15
for i in range(nframe):
    p.camera_position = [
        (15 * np.cos(i * np.pi / 45.0), 5.0, 15 * np.sin(i * np.pi / 45.0)),
        (0, 0, 0),
        (0, 1, 0),
    ]
    p.write_frame()

# Close movie and delete object
p.close()
# %%
# .. tags:: plot