sehan2
sehan2

Reputation: 1835

Is it possible to make a specific color of an image transparent in bokeh?

I have a 2D array with three different values [-1,0,1]. I have specified a custom bokeh color palette to give each value a different color.

I overlay this three valued image onto another image with 256 gray values.

For visual purposes I want make all values of -1 in three valued image transparent, i.e. I want to give the image glyph multiple alpha values.

Is there a way to achieve this in bokeh?

Here is some example code of plotting an image with a color palette: bokeh color image example

Upvotes: 1

Views: 848

Answers (1)

Eugene Pakhomov
Eugene Pakhomov

Reputation: 10652

You can specify alpha in palettes:

from bokeh.io import show
from bokeh.plotting import figure

p = figure()
p.image(image=[[[-1, 0, 1],
                [1, -1, 0],
                [0, 1, -1]]],
        x=[0], y=[0], dw=[1], dh=[1],
        palette=['rgba(0, 0, 0, 0)', 'red', 'blue'])

show(p)

Upvotes: 3

Related Questions