| 1 |
""" |
| 2 |
.. _linked_views_example: |
| 3 |
|
| 4 |
Linked Views in Subplots |
| 5 |
~~~~~~~~~~~~~~~~~~~~~~~~ |
| 6 |
|
| 7 |
This example demonstrates how to create linked views in PyVista subplots |
| 8 |
using :func:`~pyvista.Plotter.link_views`, where camera movements |
| 9 |
in one view are synchronized with other views. This is particularly useful when comparing |
| 10 |
different versions or representations of the same model. |
| 11 |
|
| 12 |
""" |
| 13 |
|
| 14 |
import numpy as np |
| 15 |
import pyvista as pv |
| 16 |
from pyvista import examples |
| 17 |
|
| 18 |
pv.set_plot_theme('document') |
| 19 |
|
| 20 |
# download mesh |
| 21 |
mesh = examples.download_cow() |
| 22 |
|
| 23 |
decimated = mesh.decimate_boundary(target_reduction=0.75) |
| 24 |
|
| 25 |
pl = pv.Plotter(shape=(1, 2), border=False) |
| 26 |
pl.subplot(0, 0) |
| 27 |
pl.add_text('Original mesh', font_size=24) |
| 28 |
pl.add_mesh(mesh, show_edges=True, color=True) |
| 29 |
pl.subplot(0, 1) |
| 30 |
pl.add_text('Decimated version', font_size=24) |
| 31 |
pl.add_mesh(decimated, color=True, show_edges=True) |
| 32 |
|
| 33 |
pl.link_views() # link all the views |
| 34 |
# Set a camera position to all linked views |
| 35 |
pl.camera_position = pv.CameraPosition( |
| 36 |
position=(15, 5, 0), focal_point=(0, 0, 0), viewup=(0, 1, 0) |
| 37 |
) |
| 38 |
|
| 39 |
pl.open_gif('linked.gif') |
| 40 |
# Update camera and write a frame for each updated position |
| 41 |
nframe = 15 |
| 42 |
for i in range(nframe): |
| 43 |
pl.camera_position = pv.CameraPosition( |
| 44 |
position=(15 * np.cos(i * np.pi / 45.0), 5.0, 15 * np.sin(i * np.pi / 45.0)), |
| 45 |
focal_point=(0, 0, 0), |
| 46 |
viewup=(0, 1, 0), |
| 47 |
) |
| 48 |
pl.write_frame() |
| 49 |
|
| 50 |
# Close movie and delete object |
| 51 |
pl.close() |
| 52 |
# %% |
| 53 |
# .. tags:: plot |