pyvista.DataSetMapper.set_scalars#

DataSetMapper.set_scalars(scalars, scalars_name, n_colors=256, scalar_bar_args=None, rgb=None, component=None, preference='point', custom_opac=False, annotations=None, log_scale=False, nan_color=None, above_color=None, below_color=None, cmap=None, flip_scalars=False, opacity=None, categories=False, clim=None)[source]#

Set the scalars on this mapper.

Parameters:
scalarsnumpy.ndarray

Array of scalars to assign to the mapper.

scalars_namestr

If the name of this array exists, scalars is ignored. Otherwise, the scalars will be added to the existing dataset and this parameter is the name to assign the scalars.

n_colorsint, default: 256

Number of colors to use when displaying scalars.

scalar_bar_argsdict, optional

Dictionary of keyword arguments to pass when adding the scalar bar to the scene. For options, see pyvista.Plotter.add_scalar_bar().

rgbbool, default: False

If an 2 dimensional array is passed as the scalars, plot those values as RGB(A) colors. rgba is also an accepted alias for this. Opacity (the A) is optional. If a scalars array ending with "_rgba" is passed, the default becomes True. This can be overridden by setting this parameter to False.

componentint, optional

Set component of vector valued scalars to plot. Must be nonnegative, if supplied. If None, the magnitude of the vector is plotted.

preferencestr, default: ‘Point’

When dataset.n_points == dataset.n_cells and setting scalars, this parameter sets how the scalars will be mapped to the mesh. Can be either 'point' or 'cell'.

custom_opacbool, default: False

Use custom opacity.

annotationsdict, optional

Pass a dictionary of annotations. Keys are the float values in the scalars range to annotate on the scalar bar and the values are the string annotations.

log_scalebool, default: False

Use log scale when mapping data to colors. Scalars less than zero are mapped to the smallest representable positive float.

nan_colorpyvista.ColorLike, optional

The color to use for all NaN values in the plotted scalar array.

above_colorpyvista.ColorLike, optional

Solid color for values below the scalars range (clim). This will automatically set the scalar bar above_label to 'above'.

below_colorpyvista.ColorLike, optional

Solid color for values below the scalars range (clim). This will automatically set the scalar bar below_label to 'below'.

cmapstr, list, or pyvista.LookupTable

Name of the Matplotlib colormap to use when mapping the scalars. See available Matplotlib colormaps. Only applicable for when displaying scalars. colormap is also an accepted alias for this. If colorcet or cmocean are installed, their colormaps can be specified by name.

You can also specify a list of colors to override an existing colormap with a custom one. For example, to create a three color colormap you might specify ['green', 'red', 'blue'].

This parameter also accepts a pyvista.LookupTable. If this is set, all parameters controlling the color map like n_colors will be ignored.

flip_scalarsbool, default: False

Flip direction of cmap. Most colormaps allow *_r suffix to do this as well.

opacitystr or numpy.ndarray, optional

Opacity mapping for the scalars array. A string can also be specified to map the scalars range to a predefined opacity transfer function (options include: ‘linear’, ‘linear_r’, ‘geom’, ‘geom_r’). Or you can pass a custom made transfer function that is an array either n_colors in length or shorter.

categoriesbool, default: False

If set to True, then the number of unique values in the scalar array will be used as the n_colors argument.

climSequence, optional

Color bar range for scalars. Defaults to minimum and maximum of scalars array. Example: (-1, 2).