2015-11-02 95 views
1

我想绘制一个基本的条形图,但我一直看到一个名为“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

你得到一个错误,但一切似乎罚款从groupBar()参数更改为stack,这是否意味着该地块仍然出现? StopIteration是唯一的想法,还是更多? – Leb

+0

的意思是,代码看起来很好。没有情节显示。我会编辑它。 – DrWolfe

回答

2

UPDATE这个答案是过时的,不会与背景虚化的版本较新,0.10

请参考recent documentation工作



您传递的是无效输入。从doc

(快译通,OrderedDict,列表,数组和DataFrames有效输入)

这是他们对那里的例子:

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) 

amountdict_values()不会被接受。我不确定你的bugrlary_dict是什么,但是为Bar(),我假设你的months是标签。这应该工作的背景虚化的例子假设len(bugrlary_dict) == 12

输出:

enter image description here

1

Bokeh 0.12.5,你可以做到这一点通过以下方式:

from bokeh.charts import Bar, output_file, show 

# best support is with data in a format that is table-like 
data = { 
    'sample': ['1st', '2nd', '1st', '2nd', '1st', '2nd'], 
    'interpreter': ['python', 'python', 'pypy', 'pypy', 'jython', 'jython'], 
    'timing': [-2, 5, 12, 40, 22, 30] 
} 

# x-axis labels pulled from the interpreter column, grouping labels from sample column 
bar = Bar(data, values='timing', label='sample', group='interpreter', 
     title="Python Interpreter Sampling - Grouped Bar chart", 
     legend='top_left', plot_width=400, xlabel="Category", ylabel="Language") 

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

输出:

enter image description here

如果你想有一个堆积条形图