Depth of Field Plotting#

Download Python source code | Download Jupyter notebook

Highlight part of a plot using enable_depth_of_field().

import numpy as np
import pyvista as pv
from pyvista import examples

Generate a Bunch of Bunnies#

Create many bunnies using the glyph filter.

# download the stanford bunny and rotate it into a good position
mesh = examples.download_bunny()
mesh = mesh.rotate_x(90, inplace=False).rotate_z(90, inplace=False).scale(4)

# We use a uniform grid here simply to create equidistantly spaced points for
# our glyph filter
grid = pv.ImageData(dimensions=(4, 3, 3), spacing=(3, 1, 1))

bunnies = grid.glyph(geom=mesh, scale=False, orient=False)
bunnies
PolyData (0x7fd38032ce20)
  N Cells:    2500236
  N Points:   1294092
  N Strips:   0
  X Bounds:   -2.475e-01, 9.235e+00
  Y Bounds:   -3.788e-01, 2.244e+00
  Z Bounds:   1.319e-01, 2.749e+00
  N Arrays:   0


Show the Plot Without Enabling Depth of Field#

# convert points into rgba colors
colors = bunnies.points - bunnies.bounds[::2]
colors /= colors.max(axis=0)
colors *= 255
colors = colors.astype(np.uint8)

# obtained camera position with `cpos = pl.show(return_cpos)`
cpos = pv.CameraPosition(
    position=(11.62, -1.28, 1.534),
    focal_point=(4.135, 1.48, 1.271),
    viewup=(-0.0352, -0.0004, 1.0),
)

# Since we're using physically based rendering (PBR), let's also download a
# skybox cubemap use it as an environment texture. For PBR to work well you
# should have a environment texture.
cubemap = examples.download_sky_box_cube_map()

pl = pv.Plotter()
pl.background_color = 'w'
pl.add_mesh(bunnies, scalars=colors, rgb=True, pbr=True, metallic=0.85)
pl.camera_position = cpos
pl.set_environment_texture(cubemap)
pl.show()
depth of field

Show the Plot While Enabling Depth of Field#

depth of field

Tags: plot

Total running time of the script: (0 minutes 21.571 seconds)

Gallery generated by Sphinx-Gallery