pyvista.opacity_transfer_function

pyvista.opacity_transfer_function#

opacity_transfer_function(mapping, n_colors, interpolate: bool = True, kind='quadratic')[ソース]#

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.interp1d is used if available, otherwise np.interp is used. The kind argument controls the kind of interpolation for interp1d.

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)) where x is the range from -a to +a and a is the value given in the mapping string. Default is a=10 for 'sigmoid' mapping.

パラメータ:
mappinglist[float] | str

The opacity mapping to use. Can be a str name of a predefined mapping including 'linear', 'geom', 'sigmoid', 'sigmoid_1-10,15,20', and foreground. Append an '_r' to any of those names (except foreground) to reverse that mapping. The mapping can also be a custom user-defined array/list of values that will be interpolated across the n_color range.

n_colorsint

The number of colors that the opacities must be mapped to.

interpolatebool

すべての色に対して不透明度のマッピングを補間するかどうかのフラグ.

kindstr

The interpolation kind if interpolate is True and scipy is available. If scipy is not available, linear interpolation is always used. Options are:

  • 'linear'

  • 'nearest'

  • 'zero'

  • 'slinear'

  • 'quadratic'

  • 'cubic'

  • 'previous'

  • 'next'

戻り値:
numpy.ndarray

Array of numpy.uint8 values n_colors long containing the [0-255] opacity mapping values.

>>> 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)