gpt4 book ai didi

python - 使用 Bokeh 绘制条形图

转载 作者:太空宇宙 更新时间:2023-11-04 00:59:40 24 4
gpt4 key购买 nike

我正在尝试绘制基本条形图,但我一直看到名为“StopIteration”的错误。我在看一个例子,代码看起来不错:

amount = bugrlary_dict.values()
months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]

print len(amount)
print len(months)
bar = Bar(amount, months, filename="bar.html")

bar.title("Bar Chart of the Amount of Burglaries").xlabel("Months").ylabel("Amount")
bar.show()

最佳答案

更新 此答案已过时,不适用于 0.10 更新的 Bokeh 版本

请引用recent documentation



您传递的输入无效。来自doc :

(dict, OrderedDict, lists, arrays and DataFrames are valid inputs)

这是他们在那里的例子:

from collections import OrderedDict
from bokeh.charts import Bar, output_file, show

# (dict, OrderedDict, lists, arrays and DataFrames are valid inputs)
xyvalues = OrderedDict()
xyvalues['python']=[-2, 5]
xyvalues['pypy']=[12, 40]
xyvalues['jython']=[22, 30]

cat = ['1st', '2nd']

bar = Bar(xyvalues, cat, title="Stacked bars",
xlabel="category", ylabel="language")

output_file("stacked_bar.html")
show(bar)

您的数量是一个dict_values(),它不会被接受。我不确定你的 bugrlary_dict 是什么,但将它作为 Bar()data 并且我假设你的 months 是标签。假设 len(bugrlary_dict) == 12

应该可以工作

Bokeh 示例的输出:

enter image description here

关于python - 使用 Bokeh 绘制条形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33469662/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com