SBPalette#
This class is a base class for color palettes.
The default implementation describes the HSV (Hue, Saturation, Value) color palette.
- class samson.SBPalette(self: samson.SBPalette, reverse: bool = False)#
Bases:
pybind11_objectThis class is a base class for color palettes.
Constructor for HSV color palette.
- Parameters:
reverse (bool, default=False) – The reverse flag - whether the color palette is mirrored or not.
- class PaletteType(self: samson.SBPalette.PaletteType, value: SupportsInt | SupportsIndex)#
Bases:
pybind11_objectMembers:
Custom : An undefined type - a custom color palette which does not fall into any of other categories
Qualitative : A qualitative color palette type - for coding categorical information, i.e., where no particular ordering of categories is available and every color should receive the same perceptual weight.
Sequential : A sequential color palette type - for coding ordered/numeric information, i.e., going from high to low (or vice versa).
Diverging : A diverging color palette type - for coding ordered/numeric information around a central neutral value, i.e., where colors diverge from neutral to two extremes.
FlexibleDiverging : A flexible diverging color palette type - for coding ordered/numeric information around a central neutral value, i.e., where colors diverge from neutral to two extremes.
Discrete : A discrete color palette type.
- Custom = <PaletteType.Custom: 0>#
- Discrete = <PaletteType.Discrete: 5>#
- Diverging = <PaletteType.Diverging: 3>#
- FlexibleDiverging = <PaletteType.FlexibleDiverging: 4>#
- Qualitative = <PaletteType.Qualitative: 1>#
- Sequential = <PaletteType.Sequential: 2>#
- property name#
- property value#
- clone(self: samson.SBPalette) samson.SBPalette#
Returns a copy of the color palette.
- getColor(self: samson.SBPalette, x: SupportsFloat | SupportsIndex) samson.SBColor#
Return an RGBA color sampled from the palette.
- Parameters:
x (float) – Intensity value in the range
[0.0, 1.0].- Returns:
RGBA color sampled at
x.- Return type:
Examples
>>> palette = SBPaletteDefaultPalette.qualitativeHCLPastel >>> color = palette.getColor(0.5) >>> print(color) [0.599445, 0.885390, 0.848835, 1.000000]
- getColorInPaletteColorSpace(self: samson.SBPalette, x: SupportsFloat | SupportsIndex) list[float]#
Return color-space coordinates sampled from the palette.
- Parameters:
x (float) – Intensity value in the range
[0.0, 1.0].- Returns:
Color coordinates in this palette’s native color space.
- Return type:
Examples
>>> palette = SBPaletteDefaultPalette.flexibleDivergingHCLCividis >>> color = palette.getColorInPaletteColorSpace(0.75) >>> print(color) [75.0, 47.5, 72.0, 1.0]
- getColorVector(self: samson.SBPalette, x: SupportsFloat | SupportsIndex) list[float]#
Return an RGBA color sampled from the palette as floats.
- Parameters:
x (float) – Intensity value in the range
[0.0, 1.0].- Returns:
Four floats
[red, green, blue, alpha]sampled atx.- Return type:
list[float]
Examples
>>> palette = SBPaletteDefaultPalette.divergingHCLBlue2Red >>> color = palette.getColorVector(1.0) >>> print("[" + ", ".join(f"{x:.5g}" for x in color) + "]") # print only 5 digits [0.55801, 0.025099, 0.23243, 1]
- static getValueAlongLinearTrajectory(y1: SupportsFloat | SupportsIndex, y2: SupportsFloat | SupportsIndex, power: SupportsFloat | SupportsIndex, x: SupportsFloat | SupportsIndex) float#
Returns a value along the linear trajectory or a power-transformed curve. :param y1: The start of the trajectory :type y1: float :param y2: The end of the trajectory :type y2: float :param power: A power parameter for the value x; if the power is equal to 1.0 the trajectory is linear, else it is a power-transformed curve :type power: float :param x: A value, should be in the range [0.0, 1.0]. :type x: float
- Returns:
The value along the trajectory
- Return type:
float
- static getValueAlongTriangularTrajectory(y1: SupportsFloat | SupportsIndex, ymax: SupportsFloat | SupportsIndex, y2: SupportsFloat | SupportsIndex, power: SupportsFloat | SupportsIndex, x: SupportsFloat | SupportsIndex) float#
Returns a value along the triangular trajectory with linear or power-transformed curves.
- Parameters:
y1 (float) – The start of the trajectory
ymax (float) – The max value on the trajectory that defines the triangular shape. If it is smaller than y1 or y2 then it defaults to the linear trajectory between y1 and y2.
y2 (float) – The end of the trajectory
power (float) – A power parameter for the value x; if the power is equal to 1.0 the trajectories that constitute the triangular trajectory are linear, else they are power-transformed curves
x (float) – A value, should be in the range [0.0, 1.0].
- Returns:
The value along the “triangular” trajectory
- Return type:
float
- Custom = <PaletteType.Custom: 0>#
- Discrete = <PaletteType.Discrete: 5>#
- Diverging = <PaletteType.Diverging: 3>#
- FlexibleDiverging = <PaletteType.FlexibleDiverging: 4>#
- Qualitative = <PaletteType.Qualitative: 1>#
- Sequential = <PaletteType.Sequential: 2>#
- property isSerializable#
Returns True when the class is serializable
- property name#
The color palette’s name.
- property reverseFlag#
The reverse flag - whether the color palette is mirrored or not.
- property type#
The color palette’s type.