Color bars

ipyscales includes widgets for visualising color maps as color bars, and for manually editing color maps.

Let’s define two simple color maps first:

In [1]:
import ipyscales
In [2]:
cm = ipyscales.LinearColorScale(
    range=('blue', 'green'),
    domain=(1000, 5000)
cm_div = ipyscales.LinearColorScale(
    range=('blue', 'white', 'red'),
    domain=(-1, 0, 1)

Next, let us define a color bar for the first color map:

In [3]:
colorbar = ipyscales.ColorBar(colormap=cm, length=300)
assert colorbar.colormap is cm
In [4]:

The orientation of the color bar can be made horizontal as well:

In [5]:
ipyscales.ColorBar(colormap=cm_div, length=300, orientation='horizontal')

The color map can include transparent colors, and the color bar also supports this:

In [6]:
cm_div_transp = ipyscales.LinearColorScale(
    range=('rgba(0, 0, 255, 0.5)', 'white', 'rgba(255, 0, 0, 0.5)'),
    domain=(-1, 0, 1)
In [7]:
ipyscales.ColorBar(colormap=cm_div_transp, length=200)

The editor ColorMapEditor can be used to manually edit the color map. The actions you can do are: - Change the color of a stop by double-clicking the corresponding handle. - Change the location of stops by dragging the handles.

In [8]:
    colormap=cm_div_transp, length=400, orientation='horizontal')

Future features planned for the editor include: - Adding new stops. - Removing stops. - Modifying the stop location by numeric input. - UI for changing opacity of a color stop.

In [ ]: