【发布时间】:2018-01-27 01:23:07
【问题描述】:
我正在尝试在 python 中使用bokeh 对我的图进行交互式分析。
我的数据存储在pandas.Dataframe。我想要一个以列名作为标签的图例。但是,bokeh 会改为从相应列中提取值。
import pandas as pd
from bokeh.plotting import figure
from bokeh.io import output_notebook, show
from bokeh.models import ColumnDataSource
output_notebook()
BokehJS 0.12.13 成功加载。
df = pd.DataFrame({'accuracy': np.random.random(10)}, index=pd.Index(np.arange(10), name='iteration'))
df
输出:
accuracy
iteration
0 0.977427
1 0.057319
2 0.307741
3 0.127390
4 0.662976
5 0.313618
6 0.214040
7 0.214274
8 0.864432
9 0.800101
现在剧情:
p = figure(width=900, y_axis_type="log")
source = ColumnDataSource(df)
p.line(x='iteration', y='accuracy', source=source, legend='accuracy')
show(p)
所需的输出,通过添加空格获得:legend='accuracy'+' ':
虽然我已经达到了我的目标,但这种方法并不能让我满意。我认为,应该有更优雅和正式的方式来区分列名和图例标签。
【问题讨论】: