简体   繁体   中英

Hover image_rgba Bokeh

I'd like to be able to hover over a RGBA image using Bokeh. For this purpose, I'd like to specify a channel as the value when hovering or another data with the same shape. For example, here it follows a minimal example, where I'd like to display a pixel's alpha value on hover, which does not work:

from __future__ import division

import numpy as np

from bokeh.plotting import figure, show

N = 20
rgba = np.empty((N,N, 4), dtype=np.uint8)
for i in range(N):
    for j in range(N):
        rgba[i, j, 0] = int(i/N*255)
        rgba[i, j, 1] = 158
        rgba[i, j, 2] = int(j/N*255)
        rgba[i, j, 3] = 255

img = np.squeeze(rgba.view(np.uint32))
data = dict(image=[img],
    x=[0],
    y=[0],
    dw=[20],
    dh=[10],
    value=[rgba[:,:,3]])

TOOLTIPS = [
    ("x", "$x"),
    ("y", "$y"),
    ("value", "@value")
]

# must give a vector of images
p = figure(plot_width=400, plot_height=400, x_range=(0, 20), y_range=(0, 10), tools='hover,wheel_zoom', tooltips=TOOLTIPS)
p.image_rgba(source=data, image='image', x='x', y='y', dw='dw', dh='dh')
show(p) 

Is it possible to provide this kind of visualisation with Bokeh?

While implementing Image hover in Bokeh, I discussed the possibility of supporting ImageRGBA hover as well but we were not entirely clear how hover should behave in that case. As of Bokeh 1.0.4, ImageRBGA hover in Bokeh is not yet supported but if you file a GitHub issue, I think that could reopen discussion and get this feature implemented.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM