散景传说无法找到场

时间:2018-01-10 15:28:26

标签: python-2.7 jupyter-notebook bokeh

我在bokeh中使用Jupyter notebook(之前从未使用过此库)绘制折线图,​​我试图添加一个图例但我得到了以下错误:

ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

代码

d = {'col1': [1, 2], 'col2': [3, 4], 'label' : ['something', 'something']}
df = pd.DataFrame(data=d)


trend = figure( tools="pan,box_zoom,reset,save",title="trends")

trend.line(source = df, x ='col1', y = 'col2', line_color="red", legend ='label')

show(p)

到目前为止,我已尝试移动legend字段并指定dataframe名称。

1 个答案:

答案 0 :(得分:1)

当DataFrame作为figure参数传递时,这些似乎实际上是source中的一个小错误。在这种情况下,DataFrame会在内部自动转换为Bokeh ColumnDataSource,但显然不会很快发生。但是,修复很简单,因为您可以自己创建ColumnDataSource

import pandas as pd
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from bokeh.io import output_file, show

d = {'col1': [1, 2], 'col2': [3, 4], 'label' : ['something', 'something']}
df = pd.DataFrame(data=d)

p = figure( tools="pan,box_zoom,reset,save",title="trends")

source = ColumnDataSource(df)
p.line(source=source, x ='col1', y = 'col2', line_color="red", legend ='label')

show(p)

请在GitHub issue tracker上使用此代码提交错误报告。