Hello everyone, first of all, please go easy on me, I am new in Python and here.
I am trying to create a engineering tool with a simple layout. Everything works out except some formatting and legend labels.
I understand that data source columns are essential for interactivity between bokeh serve and code. If I don’t use datasourcecolumns, the updates on the browser does not reflect back to code. So, I am creating all my figures with datasourcecolumns. However, I have a problem with labels.
In my datasourcecolumns, I have n array. The first array is x_vector which is basically an array between xmax and xmin. With the same size, I have y_vectors. All y_vectors have the same size with x_vector, as it should be.
So, I line plot x_vector and y_vector1 first. Then, x_vector and y_vector2. Then, next until all n y_vector is plotted.
Question is how can I label the y_vectors in an interactive way? Assume that n=6, so I have 6 y_vector, 1 x_vector, all have (assume) 1000 element. But, my label vector is only 6 element long since I have only 6 y_vector! So, I cannot use the same source for both my x and y elements and labels.
I have tried to use lists as keys in dictionary, but I couldn’t manage to work it out. I thought giving x and y as a list of vectors would work but, it didn’t because y=‘b’[0] is not valid.
from bokeh.io import show
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource
import numpy as np
import matplotlib.pyplot as plt
a = np.arange(0,100,1)
b1 = a*2
b2 = a*3
labels = ["b1","b2"]
sourcedict = {"a": [a], "b": [b1,b2], "c": labels}
source = ColumnDataSource(sourcedict)
fig1 = figure()
# fig1.line(x='a', y='b', legend_label = 'c', source=source)
#BokehUserWarning: ColumnDataSource's columns must be of the same length. Current lengths: ('a', 1), ('b', 2), ('c', 2)
fig1_alt = figure()
fig1_alt.line(x='a'[0], y='b'[0], legend_label = 'c'[0])