Hi all,
I have written some code that uses the bokeh-server to read-in CSV files from a given folder and uses multi-line plot in conjunction with CheckboxGroup to toggle each CSV file.
I am glad to say I have done this successfully except for one issue: line_color isn’t properly assigning colors when passing in list of lists from ColumnDataSource objects.
The graph is being displayed properly, but the line colors show up as all grey as seen in the image below:
I am creating this plot using primarily this batch of code withing a classmethod:
obj = cls()
obj.source1 = ColumnDataSource(data=dict(xs=, ys=))
obj.source2 = ColumnDataSource(data=dict(xs=, ys=))
obj.source3 = ColumnDataSource(data=dict(xs=, ys=))
fns = get_filenames(path_to_dir, suffix=’.csv’)
obj.toggle = CheckboxGroup(labels=fns, active=[0])
print(obj.toggle)
colors= [’#3498DB’, ‘F1C40F’, ‘#16A085’, ‘#C0392B’]
toolset = “crosshair,pan,reset,resize,save,wheel_zoom”
plot = figure(plot_height=400,
plot_width=800,
tools=toolset,
x_axis_type=“datetime”
)
plot.multi_line(‘xs’, ‘ys’, source=obj.source1,
line_width=3,
line_color=[‘red’,‘green’,‘blue’,‘purple’]
)
plot.multi_line(‘xs’, ‘ys’, source=obj.source2,
line_width=3,
line_color=[‘red’,‘green’,‘blue’,‘purple’]
)
plot.multi_line(‘xs’, ‘ys’, source=obj.source3,
line_width=3,
line_color=[‘red’,‘green’,‘blue’,‘purple’]
)
obj.plot = plot
obj.update_data()
obj.inputs = VBoxForm(
children=[
obj.toggle
]
)
obj.children.append(obj.inputs)
obj.children.append(obj.plot)
return obj
``
xs and ys are list of lists and are being updated using the follow example code:
df_list = load_csv_to_dflist(path_to_dir, suffix=".csv")
x1 = x2 = x3 = []
y1 = y2 = y3 = []
print(self.toggle.active, "self.toggle")
for p in self.toggle.active:
if p == 0:
DT = df_list[p].Date.tolist()
x1 = [DT, DT, DT, DT]
y1 = [df_list[p].C.tolist(),
df_list[p].D.tolist(),
df_list[p].Cases.tolist(),
df_list[p].Deaths.tolist()]
if p == 1:
DT = df_list[p].Date.tolist()
x2 = [DT, DT, DT, DT]
y2 = [df_list[p].C.tolist(),
df_list[p].D.tolist(),
df_list[p].Cases.tolist(),
df_list[p].Deaths.tolist()]
if p == 2:
DT = df_list[p].Date.tolist()
x3 = [DT, DT, DT, DT]
y3 = [df_list[p].C.tolist(),
df_list[p].D.tolist(),
df_list[p].Cases.tolist(),
self.source1.data = dict(xs=x1, ys=y1)
self.source2.data = dict(xs=x2, ys=y2)
self.source3.data = dict(xs=x3, ys=y3)
df_list[p].Deaths.tolist()]
``
If you would like to see the full code you can go here: Toggle2_small.py · GitHub
Thanks,
Andy