
Hi, this should be simple, but I can’t work it out.
I am trying to load an image as a background for a line plot.
This works, but I don’t how to control the size of the image so it matches the plot.
import pandas as pd
import numpy as np
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, ImageURL, Div, Row
from bokeh.io import show, output_notebook
output_notebook()
dates = pd.date_range("20210101", periods=6)
df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list("ABCD"))
df.rename_axis('Date', axis=0, inplace=True)
source = ColumnDataSource(df)
url = 'https://images.unsplash.com/photo-1586061968253-7bf5724aab7b?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxMTc3M3wwfDF8c2VhcmNofDE0fHxiYW1ib298ZW58MHx8fHwxNjQ5NjgxMzA0&ixlib=rb-1.2.1&q=80&w=2000'
p = figure(aspect_ratio = 16/9)
p.line(x='Date',
y='A',
source = source,
color='green')
d1 = Div(text = '<div style="position: absolute; left:-570px; top:10px"><img src=' + url + ' style="aspect_ratio : 16/9; opacity: 0.2;"></div>')
show(Row(p, d1))
I thought this seemed like the better method to control the size, but I can’t get both the line and the background to appear:
p = figure(aspect_ratio = 16/9)
p.image_url(url=[url],
x=0, y=0, w=1, h=1, anchor="bottom_left", alpha=0.2)
p.line(x='Date',
y='A',
source = source,
color='green')
show(p)
Thanks


