Plotter.add_background_image

Plotter.add_background_image#

Plotter.add_background_image(
image_path: str | Path,
*,
scale: float = 1.0,
auto_resize: bool = True,
as_global: bool = True,
) None[source]#

Add a background image to a plot.

Parameters:
image_pathstr

Path to an image file.

scalefloat, default: 1.0

Scale the image larger or smaller relative to the size of the window. The image height is scaled to the height of the render window, or of the subplot when as_global=False. Its aspect ratio is preserved, so the image is cropped horizontally where it is too wide to fit.

auto_resizebool, default: True

Resize the background when the render window changes size.

as_globalbool, default: True

When multiple render windows are present, setting as_global=False will cause the background to only appear in one window.

Examples#

Download Python source code | Download Jupyter notebook

>>> import pyvista as pv
>>> from pyvista import examples
>>> pl = pv.Plotter()
>>> actor = pl.add_mesh(pv.Sphere())
>>> pl.add_background_image(examples.mapfile)
>>> pl.show()
../../../_images/pyvista-Plotter-add_background_image-5b1c1eeea926b67f_00_00.png