Bokeh - Tooltips Not working with image_rgba

I’ve asked this question on Stackoverflow as well (python - Does bokehs `image_rgba()` support hovertools? - Stack Overflow), but got no response.

This is functionality that I can’t make rhyme or reason of. I want to use the default tooltip (hovertools) for line glyphs, circle glyphs and image_rgba’s. Here is my super simple code:

p = figure(width=self.width, height=self.height, x_range=self.x_range, y_range=self.y_range, tools="hover")

line_glyphs = p.segment(
             x0='hex_x', y0='hex_y', x1='mercator_x', y1='mercator_y', 
             source=source, 
             line_width=2, line_alpha=0.8,
             line_color='fill_color', line_dash='line_dash')
        
img_glyphs = p.image_rgba(
            image='hex_rgba',
            x='hex_x', y='hex_y',
            dw='hex_size', dw_units="screen",
            dh='hex_size', dh_units="screen",
            anchor="center_center",
            source=source)
        
circle_glyphs = p.circle(
            x='mercator_x', y='mercator_y', 
            size=8, fill_color='fill_color', line_color='gold', 
            source=source)

show(p)

Everything renders perfectly. I’ve manually checked all my data in ‘source’ and it’s correct.
However, bokeh’s default tooltips show up for the lines and circles on hover, but not for the image.
Why? Is there something fundamentally wrong? I’ve checked documentation but image_rgba does support tooltips. The python console and the js console show no errors of any sort.

Any tips even on how to debug this issue would help…

Older versions of Bokeh didn’t support hover in image glyphs, what version are you using? It is always advised to state relevant version information with every support question.

I am using the latest version, just reinstalled it yesterday.

I think I got slightly further in finding the root cause of the problem, and it seems to be in bokeh itself.
This code snippet does NOT work (tooltips show for lines and circles, but not for image_rgba’s):

from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource
import numpy as np
from PIL import Image

# Create the Bokeh figure
p = figure(width=1500, height=1000, tools="hover")

# Create the sample data (these two lines are the problem!)
x = np.array([16500000, 17500000, 13500000])
y = np.array([4500000, 4400000, 4600000])

im = Image.open("image.png") # just replace any image that you want here
imarray = np.flipud(np.array(im.convert("RGBA")))
img = imarray.view("uint32").reshape(imarray.shape[:2])

# Create a ColumnDataSource for the data
source = ColumnDataSource(data=dict(x=x, y=y, img=[img] * len(x)))

# Create the glyphs
circle_glyphs = p.circle(x='x', y='y', size=10, fill_color='blue', source=source, name='circles', line_color='black', line_width=2, fill_alpha=0.8)

line_glyphs = p.line(x='x', y='y', line_color='green', line_width=2, source=source, name='lines',)

image_glyphs = p.image_rgba(image='img', name="image", x='x', y='y', 
                            dw=100, dw_units="screen",dh=100, dh_units="screen",
                            source=source, anchor='center_center')

# Show the Bokeh plot
show(p)

However, when I change x and y’s to “smaller” numbers (like 1, 2, 3, etc.) the tooltips show up perfectly for the image_rgba’s (along with the lines and circles):

# Create the sample data
x = np.array([1, 2, 3])
y = np.array([4, 5, 6])

Is this a known issue?

Investigating further, it seems there is an inflection point somewhere around 10,000 for x and/or y, where the tooltip for image_rgba stops working.

Around 10,000, I can see a tooltip for some portions of the image very briefly

Can someone confirm they see the same problems when running the aforementioned code?

Nobody seems to be addressing this, so can I submit this as a bug?
I think it has to do with bokeh’s scaling not working well with image_rgba’s tooltip location (I believe they are rendered “off-screen”)

This is volunteer forum, with participants all over the word in different timezones, e.g I just woke up. There is no SLA. Discussion here are asynchronous and often span several days, that is where you should set your expectations. I hope to be able to actually run your code later today to try and see whether it seems like a bug or some usage problem or something else.

I only just noticed you are specifying screen units, and I am fairly certain that is the issue. Feel free to open an issue, but it’s uncertain what can be done. Bokeh performs spatial indexing in data-space in order to make hit-testing efficient, but that does not work very well with screen units since any pan, zoom, etc changes the data-space coordinates and invalidates the index. We might end up simply documenting the incompatibility.

Ah I see, so I guess it is a known “bug” or maybe known “functionality issue”.
I understand your explanation and thanks!

For a workaround (for now) I just made an invisible glyph (alpha channel set to transparent with the tooltip I actually wanted) overlaid on the image_rgba.

Another workaround I considered given your explanation was manually converting pixels (screen units) to coordinate units to display the image_rgba but I found this a bit involved given bokeh might resize the figure (let’s say width=100, height=200 but x_range=(100,500), y_range=(100,1000000))

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.