vis_tools.Gradient module

This file contains a class for doing Python-side color gradients. The Gradient class is a gradient with an arbitrary number of color stops. Since Gradient is derived from the Vis-Tools gradient.js, the same style text representations of gradients can be used.


  • Gradient - a sampleable color gradient.


gradient = Gradient("[email protected],[email protected],[email protected],[email protected]")
color = gradient.sample(0.5)
class vis_tools.Gradient.Gradient(spec='')

Bases: object

Class for sampleable color gradients.

This class lets you create a color gradient with an arbitrary number of color stops on a normalized range from 0 to 1. You then sample the gradient with a normalized value from 0 to 1 to get a color out of the gradient.

This class is based on the Vis-Tools gradient.js. However it does not support the “,r” or “,q<steps>” suffixes supported by gradient.js.

The spec format is:


  • color - Color objects representing the stop colors

  • loc - Ordered values in range(0, 1) representing the normalized locations of the gradient stops.


ValueError – if spec is invalid.


Sample the gradient to get a color at a particular location.


A Color object for the color at the sample point.

Return type


  • loc0to1 (float) – A normalized value in the range(0, 1) at which

  • to sample the gradient color. (point) –