Hello,
I am having difficulties to create an image plot with a column data source from a DataFrame. This results in the following error message:
BokehUserWarning: ColumnDataSource’s columns must be of the same length
``
My test code:
from bokeh.client import push_session
from bokeh.models import ColumnDataSource
from bokeh.plotting import curdoc, figure
import numpy as np
from pandas import DataFrame
Starting bokeh server from here
import subprocess
import time
args = [‘python’, ‘-m’, ‘bokeh’, ‘serve’]
p = subprocess.Popen(args)
time.sleep(1) # time to wait might be longer on other PC
defining CDS
data1 = np.random.rand(5, 20)
df1 = DataFrame(data = data1)
this is working
source = ColumnDataSource(dict(x=[0],y=[0],dw=[10],dh=[10],image=[data1]))
this is not working
source = ColumnDataSource(dict(x=[0],y=[0],dw=[10],dh=[10],image=df1))
image
size = 300
ranges = (0,10)
image_plot = figure(title = ‘Image’, plot_width = size, plot_height = size,
x_range=ranges, y_range=ranges)
image_plot.image(image = ‘image’, source = source, x = ‘x’, y=‘y’,
dw=‘dw’, dh=‘dw’, palette=“Viridis256”)
show
session = push_session(curdoc())
session.show(image_plot)
session.loop_until_closed()
``
When I replace
source = ColumnDataSource(dict(x=[0],y=[0],dw=[10],dh=[10],image=df1))
``
with
source = ColumnDataSource(dict(x=[0],y=[0],dw=[10],dh=[10],image=[data1]))
``
the image is normally displayed.
What is the error in my attempt to use a DataFrame?
Thanks
Daniel