Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 尝试将Bokeh Widget复选框组与多行及其attibute一起使用时出现值错误;可见的;_Python_Python 2.7_Checkbox_Bokeh - Fatal编程技术网

Python 尝试将Bokeh Widget复选框组与多行及其attibute一起使用时出现值错误;可见的;

Python 尝试将Bokeh Widget复选框组与多行及其attibute一起使用时出现值错误;可见的;,python,python-2.7,checkbox,bokeh,Python,Python 2.7,Checkbox,Bokeh,在包含35行的Bokeh绘图中工作时,当尝试使用复选框小部件使其可见和不可见时,在选中复选框的一个元素时会出现此错误,并且没有行消失。记录如下: PS C:\Users\407334\pad-s100> bokeh serve plot4.py 2017-02-01 14:42:36,759 Starting Bokeh server version 0.12.4 2017-02-01 15:09:13,523 Starting Bokeh server on port 5006 with

在包含35行的Bokeh绘图中工作时,当尝试使用复选框小部件使其可见和不可见时,在选中复选框的一个元素时会出现此错误,并且没有行消失。记录如下:

PS C:\Users\407334\pad-s100> bokeh serve plot4.py
2017-02-01 14:42:36,759 Starting Bokeh server version 0.12.4
2017-02-01 15:09:13,523 Starting Bokeh server on port 5006 with applications at paths ['/plot4']
2017-02-01 15:09:13,525 Starting Bokeh server with process id: 11116
2017-02-01 15:10:05,821 200 GET /plot4 (::1) 6733.00ms
2017-02-01 15:10:06,246 WebSocket connection opened
2017-02-01 15:10:06,247 ServerConnection created
2017-02-01 15:10:30,026 error handling message Message 'PATCH-DOC' (revision 1): ValueError('too many values to unpack',
)
使用的python脚本受以下因素的影响:

绘制它们的不同方法已经过测试,但误差仍然存在


这是绘图工作:

复选框。active
是从0到n-1的整数列表,因此在搜索与第0行的匹配时,第1行。。。将其转换为整数,即:

def update(attr, old, new):
    for i, element in line_set.iteritems():
        element.visible = int(i[4:]) in checkbox.active
不需要创建字典,而是可以填充一个列表,这将保留顺序,因此无需将字典的键与活动复选框匹配。我已经创建了一些熊猫数据来玩。以下代码实现了后面的idea,至少在使用python2.7的bokeh版本0.12.4中有效:

import bokeh
import bokeh.plotting

# Begin Creating some panda data
# ------------------------------
import datetime
import pandas as pd
todays_date = datetime.datetime.now().date()
cols = 20;rows = 10.
index = pd.date_range(todays_date, periods=rows, freq='D')
columns = ['col%d'%x for x in range(cols)]
data = [pd.np.arange(cols)/10.+x for x in pd.np.arange(rows)/rows]
df = pd.DataFrame(data, index=index, columns=columns)
# ----------------------------
# End Creating some panda data

p = bokeh.plotting.figure(title="Motor-Block Monitorization", 
                          width=500, plot_height=500, x_axis_type='datetime')

numlines = len(df.columns)
mypalette = bokeh.palettes.inferno(numlines)
line_list = []

for (column_names, colores) in zip(df.columns.values, mypalette):
    if column_names != 'Date' and column_names != 'Time':
        line_list += [p.line(df.index, df[column_names], color=colores)]

act = range(0, numlines)
checkbox = bokeh.models.CheckboxGroup(labels=list(df.columns.values),
                     active=act)

def update(attr, old, new):
    for i, element in enumerate(line_list):
        element.visible = i in checkbox.active

checkbox.on_change('active', update)
main_column = bokeh.layouts.row(p, checkbox)
bokeh.io.curdoc().add_root(main_column)

测试了哪些选项?@WhatsThePoint by options我指的是绘制线条的不同方式。对不起,我把你弄糊涂了。仅供参考,Bokeh
0.12.5
将内置“交互式图例”功能。@bigreddot很棒!交互式图例功能在本例中非常有用谢谢!现在它工作得很好!示例中您的代码比我的代码更清晰,谢谢。这让我有机会第一次制作一个bokeh服务器应用程序。在使用静态bokeh页面之前,我使用了大量JavaScript来管理交互。还可以使用XMLHttpRequest与服务器中的cgi程序通信。我知道bokeh服务器是仅使用python处理该问题的方法,但我需要创建一个示例。现在,在这里。
import bokeh
import bokeh.plotting

# Begin Creating some panda data
# ------------------------------
import datetime
import pandas as pd
todays_date = datetime.datetime.now().date()
cols = 20;rows = 10.
index = pd.date_range(todays_date, periods=rows, freq='D')
columns = ['col%d'%x for x in range(cols)]
data = [pd.np.arange(cols)/10.+x for x in pd.np.arange(rows)/rows]
df = pd.DataFrame(data, index=index, columns=columns)
# ----------------------------
# End Creating some panda data

p = bokeh.plotting.figure(title="Motor-Block Monitorization", 
                          width=500, plot_height=500, x_axis_type='datetime')

numlines = len(df.columns)
mypalette = bokeh.palettes.inferno(numlines)
line_list = []

for (column_names, colores) in zip(df.columns.values, mypalette):
    if column_names != 'Date' and column_names != 'Time':
        line_list += [p.line(df.index, df[column_names], color=colores)]

act = range(0, numlines)
checkbox = bokeh.models.CheckboxGroup(labels=list(df.columns.values),
                     active=act)

def update(attr, old, new):
    for i, element in enumerate(line_list):
        element.visible = i in checkbox.active

checkbox.on_change('active', update)
main_column = bokeh.layouts.row(p, checkbox)
bokeh.io.curdoc().add_root(main_column)