pyvista.opacity_transfer_function#
- opacity_transfer_function(mapping, n_colors, interpolate: bool = True, kind='linear')[source]#
Get the opacity transfer function for a mapping.
These values will map on to a scalar bar range and thus the number of colors (
n_colors) must correspond to the number of colors in the color mapping that these opacities are associated to.If interpolating,
scipy.interpolate.interp1dis used if available, otherwisenp.interpis used. Thekindargument controls the kind of interpolation forinterp1d.This returns the opacity range from 0 to 255, where 0 is totally transparent and 255 is totally opaque.
The equation to create the sigmoid mapping is:
1 / (1 + exp(-x))wherexis the range from-ato+aandais the value given in themappingstring. Default isa=10for ‘sigmoid’ mapping.- Parameters:
- mapping
list[float] |str The opacity mapping to use. Can be a
strname of a predefined mapping including'linear','geom','sigmoid','sigmoid_1-10,15,20', andforeground. Append an'_r'to any of those names (exceptforeground) to reverse that mapping. The mapping can also be a custom user-defined array/list of values that will be interpolated across then_colorrange.- n_colors
int The number of colors that the opacities must be mapped to.
- interpolatebool
Flag on whether or not to interpolate the opacity mapping for all colors.
- kind
str The interpolation kind if
interpolateisTrueandscipyis available. Ifscipyis not available, linear interpolation is always used. Options are:'linear''nearest''zero''slinear''quadratic''cubic''previous''next'
Changed in version 0.46: Linear interpolation is now always used by default. Previously, quadratic interpolation was used if
scipywas installed.
- mapping
- Returns:
numpy.ndarrayArray of
numpy.uint8valuesn_colorslong containing the [0-255] opacity mapping values.
Examples
>>> import pyvista as pv >>> # Fetch the `sigmoid` mapping between 0 and 255 >>> tf = pv.opacity_transfer_function('sigmoid', 256) >>> # Fetch the `geom_r` mapping between 0 and 1 >>> tf = pv.opacity_transfer_function('geom_r', 256).astype(float) / 255.0 >>> # Interpolate a user defined opacity mapping >>> opacity = [0, 0.2, 0.9, 0.6, 0.3] >>> tf = pv.opacity_transfer_function(opacity, 256)