parse_color

parse_color(color, opacity=None, default_color=None)

Parse color into a VTK friendly RGB(A) tuple.

If color is a sequence of RGBA floats, the opacity parameter is ignored.

Values returned will be between 0 and 1.

Parameters
colorstr or sequence

Either a string, RGB sequence, RGBA sequence, or hex color string. RGB(A) sequences should only contain values between 0 and 1. For example:

  • 'white'

  • 'w'

  • [1, 1, 1]

  • [0.5, 1, 0.7, 1]

  • '#FFFFFF'

opacityfloat, optional

Default opacity of the returned color. Used when color is not a length 4 RGBA sequence. Only opacities between 0 and 1 are allowed.

default_colorstr or sequence, optional

Default color to use when color is None. If this value is None, then defaults to the global theme color. Format is identical to color.

Returns
tuple

Either a length 3 RGB sequence if opacity is unset, or an RGBA sequence when opacity is set or the input color is an RGBA sequence.

Examples

>>> import pyvista
>>> pyvista.parse_color('blue')
(0.0, 0.0, 1.0)
>>> pyvista.parse_color('k')
(0.0, 0.0, 0.0)
>>> pyvista.parse_color('#FFFFFF')
(1.0, 1.0, 1.0)
>>> pyvista.parse_color((0.4, 0.3, 0.4, 1))
(0.4, 0.3, 0.4, 1.0)