Python bokeh AttributeError: unexpected attribute 'legend_label' to Line, possible attributes are js_event_callbacks
问题再现
在运行bokeh官方文档中的以下脚本时出现错误。
from bokeh.plotting import figure, output_file, show
# prepare some data
x = [1, 2, 3, 4, 5]
y = [6, 7, 2, 4, 5]
# output to static HTML file
output_file("lines.html")
# create a new plot with a title and axis labels
p = figure(title="simple line example", x_axis_label='x', y_axis_label='y')
# add a line renderer with legend and line thickness
p.line(x, y, legend_label="Temp.", line_width=2)
# show the results
show(p)
错误:
AttributeError: unexpected attribute 'legend_label' to Line, possible attributes are js_event_callbacks, js_property_callbacks, line_alpha, line_cap, line_color, line_dash, line_dash_offset, line_join, line_width, name, subscribed_events, tags, x or y
原因
查找后发现是版本问题 legend_label 是在Bokeh 1.4中才有, 使用 pip list
命令得知当前版本是1.0.4
参考:
https://stackoverflow.com/questions/60610367/stacked-bar-charts-bokeh-attribute-error
解决
- 升级bokeh版本
pip install --upgrade bokeh
- 依然原来版本中这个
legend_label
改为legend