Reputation: 159
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()
Upvotes: 2
Views: 4867
Reputation: 8521
In Bokeh 0.12.5, you can do it the following way:
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)
Output:
Change the parameter in Bar()
from group
to stack
if you want a stacked bar chart
Upvotes: 1
Reputation: 15953
UPDATE this answer is out of date and will not work with Bokeh versions newer than 0.10
Please refer to recent documentation
You're passing invalid input. From the doc:
(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)
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
Output from Bokeh's example:
Upvotes: 2