散景的“来源"具有不同的列长 [英] Bokeh "source" with different columns length

查看:63
本文介绍了散景的“来源"具有不同的列长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在具有散景的同一张图表中绘制几个时间序列.有些系列的长度会与其他系列不同,但我想让它们保持显示状态.

在这一点上,我有警告告诉我,源中的所有列的长度都不相同,但是Bokeh似乎会自动调整大小.

另一件重要的事情是,我需要在相同源中包含时间序列的所有"Y"值,因为我在JS中使用回调函数来创建交互式绘图.

回调为:

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');
        """)

该算法是在源的column_name上循环,以绘制/取消绘制相应的时间序列.

我可以在args=dict(source=source)中提供来源列表吗?我应该忽略警告,但是我的系列被删减了,还是应该以其他方式处理它?<​​/p>

该剧情效果很好,但是我正在尝试删除警告...

谢谢!

解决方案

我主要看到两个选项:

  • 将数据重新采样到相同的长度,但这可能不是那么容易,并且很大程度上取决于数据的属性. (如果可以进行插值或下采样等)

  • 您可以将多个line()(或任何字形)图添加到一个图形上.意味着您将数据按相同的长度分组到多个数据帧中.然后,您的Javascript将需要一点重构.您可以遍历线条的渲染器,并在其中引用相应的源.或者,您可以在javascript中禁用渲染器(以隐藏绘图)

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!

解决方案

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)

这篇关于散景的“来源"具有不同的列长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆