我正在尝试使用 Python 创建 Bokeh 条形图。 data2 是值
from bokeh.plotting import figure, output_file, show,hplot
from bokeh.charts import Bar
data2=[65.75, 48.400000000000006, 58.183333333333337, 14.516666666666666]
bar = Bar(values=data2,xlabel="beef,pork,fowl,fish",ylabel="Avg consumtion", width=400)
show(bar)
错误
TypeError: Bar() takes at least 1 argument (1 given)
我在这里做错了什么?
最佳答案
bokeh.charts
API(包括 Bar
)已于 2017 年被弃用并从 Bokeh 中删除。它不受维护和支持,因此不应以任何理由使用它观点。使用受良好支持的 bokeh.plotting
API 可以完成简单的条形图:
from bokeh.plotting import figure, show
categories = ["beef", "pork", "fowl", "fish"]
data = [65.75, 48.4, 58.183, 14.517]
p = figure(x_range=categories)
p.vbar(x=categories, top=data, width=0.9)
show(p)
有关 bokeh.plotting
中对条形图和分类图的大幅改进支持的更多信息,请参阅详细的用户指南部分 Handling Categorical Data
关于python - Bokeh 条图 |,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36959406/