问题
I am trying to plot several time series in the same chart with bokeh. Some series will have different length than the others, but I want to keep them displayed.
At this point, I have the warning telling me that all the column of the source don't have the same length, but Bokeh seems automatically adjusting sizes.
An other important thing, I need to have all the 'Y' values of the time series in the same source, as I am using a callback in JS in order to create and interactive plot.
The callback is:
callback = CustomJS(args=dict(source=source), code="""
// data contains the source.column_names keys
var data = source.get('data');
// f contains the name of the time series to be plotted
var f = cb_obj.get('value');
// For each key in the source, find the lines to be plotted
for (i = 0; i < Object.keys(data).length; i++) {
curr_key = Object.keys(data)[i];
// 'line' identifier is used to recognise columns of sources which represent Y values
if (curr_key.includes('line')) {
id_ = curr_key.split('_')[0];
associated_save = id_.concat('_save_y');
// If the time series is in the selected to be plotted, set the data to plot it
if (f.indexOf(curr_key) > -1) {
data[curr_key] = data[associated_save]
} else { // else, fixe to nan to erase it
data[curr_key] = 'nan'
}
}
}
source.trigger('change');
""")
The algorithm is to loop over the column_names of the source in order to plot / or unplot the corresponding time series.
Can I provide a list of sources here args=dict(source=source)
? should I ignore warning, but my series are cut or should I process it in an other way?
The plot works pretty well, but I am trying to remove the warning...
Thank you!
回答1:
I see mainly two options:
Resample your data to the same length, but that is probably not so easy to do and depends very much on the properties of your data. (If interpolation or downsampling is feasible etc. )
You can add several line() (or whatever glyph) plots to one figure. Means you group your data in several dataframes by the same length. Then your Javascript will need a little bit of refactoring. You can iterate over the renderers which are lines and there you have a reference to the corresponding source. Or you can disable the renderer in javascript (to hide the plot)
来源:https://stackoverflow.com/questions/42286473/bokeh-source-with-different-columns-length