用散景绘制条形图 [英] Plotting Bar Charts with Bokeh
问题描述
我正在尝试绘制基本的条形图,但我一直看到称为"StopIteration"的错误.我正在举一个例子,代码看起来不错:
I am trying to plot a basic barchart but I keep seeing an error called 'StopIteration'. I am following an example, and the code seems fine:
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()
推荐答案
UPDATE 0.10
请参考最新文档
您传递的输入无效.从文档:
You're passing invalid input. From the doc:
(dict,OrderedDict,列表,数组和DataFrame是有效输入)
(dict, OrderedDict, lists, arrays and DataFrames are valid inputs)
这是他们在那里的示例:
This is the example they have on there:
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)
您的amount
是将不被接受的dict_values()
.我不确定您的bugrlary_dict
是什么,但是将其作为Bar()
的data
,我假设您的months
是标签.假设len(bugrlary_dict) == 12
Your amount
is a dict_values()
which will not be accepted. I'm not sure what your bugrlary_dict
is but have that as the data
for the Bar()
and I'm assuming your months
is the label. That should work assuming len(bugrlary_dict) == 12
Bokeh示例的输出:
Output from Bokeh's example:
这篇关于用散景绘制条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!