Search code examples
pythonjupyter-notebookbokeh

Display base64 image inside a bokeh figure


Let’s say I have a small red bullet base64 image:

im = ‘iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==’

To display it inside my notebook I use:

from IPython import display
display.HTML(f'<img src="data:image/png;base64,{im}" />')

Now I want to draw this base64 image inside my notebook bokeh figure.

How I should proceed, for instance, if I want to draw 5 im inside a bokeh figure randomly (see below figure). ?

enter image description here


Solution

  • @DSgUY image_url do the job thanks for the idea !

    from bokeh.plotting import figure, show, output_file
    import base64
    im = 'iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='
    url = 'data:image/png;base64,'+im 
    p = figure(x_range=(0,500), y_range=(0,500))
    p.image_url( url=[url], x=300, y=300,w=100,h=100)
    show(p)