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:

[1]:
import ipyscales
[2]:
from ipyscales._example_helper import use_example_model_ids
use_example_model_ids()
[3]:
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:

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

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

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

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

[7]:
cm_div_transp = ipyscales.LinearColorScale(
    range=('rgba(0, 0, 255, 0.5)', 'white', 'rgba(255, 0, 0, 0.5)'),
    domain=(-1, 0, 1)
)
[8]:
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.

[9]:
ipyscales.ColorMapEditor(
    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.