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:
- scalars
numpy.ndarray
Array of scalars to assign to the mapper.
- scalars_name
str
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_colors
int
, default: 256 Number of colors to use when displaying scalars.
- scalar_bar_args
dict
,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 becomesTrue
. This can be overridden by setting this parameter toFalse
.- component
int
,optional
Set component of vector valued scalars to plot. Must be nonnegative, if supplied. If
None
, the magnitude of the vector is plotted.- preference
str
, 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.
- annotations
dict
,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_color
pyvista.ColorLike
,optional
The color to use for all
NaN
values in the plotted scalar array.- above_color
pyvista.ColorLike
,optional
Solid color for values below the scalars range (
clim
). This will automatically set the scalar barabove_label
to'above'
.- below_color
pyvista.ColorLike
,optional
Solid color for values below the scalars range (
clim
). This will automatically set the scalar barbelow_label
to'below'
.- cmap
str
,list
,or
pyvista.LookupTable
Name of the Matplotlib colormap to use when mapping the
scalars
. See available Matplotlib colormaps. Only applicable for when displayingscalars
.colormap
is also an accepted alias for this. Ifcolorcet
orcmocean
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 liken_colors
will be ignored.- flip_scalarsbool, default:
False
Flip direction of cmap. Most colormaps allow
*_r
suffix to do this as well.- opacity
str
ornumpy.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 then_colors
argument.- clim
Sequence
,optional
Color bar range for scalars. Defaults to minimum and maximum of scalars array. Example:
(-1, 2)
.
- scalars