У меня есть функция боке, которая строит горизонтальную гистограмму.Я получаю следующую ошибку:
AttributeError Traceback (most recent call last)
<ipython-input-149-b0fece870a18> in <module>()
----> 1 show(Show_NameBased_Chart(out_dict))
/home/rgupta/anaconda2/lib/python2.7/site-packages/bokeh/util/api.pyc in wrapper(*args, **kw)
188 @wraps(obj)
189 def wrapper(*args, **kw):
--> 190 return obj(*args, **kw)
191
192 wrapper.__bkversion__ = version
/home/rgupta/anaconda2/lib/python2.7/site-packages/bokeh/io/showing.pyc in show(obj, browser, new, notebook_handle, notebook_url)
126
127 if obj not in state.document.roots:
--> 128 state.document.add_root(obj)
129 return _show_with_state(obj, state, browser, new, notebook_handle=notebook_handle)
130
/home/rgupta/anaconda2/lib/python2.7/site-packages/bokeh/document/document.pyc in add_root(self, model, setter)
241 self._roots.append(model)
242 finally:
--> 243 self._pop_all_models_freeze()
244 self._trigger_on_change(RootAddedEvent(self, model, setter))
245
/home/rgupta/anaconda2/lib/python2.7/site-packages/bokeh/document/document.pyc in _pop_all_models_freeze(self)
921 self._all_models_freeze_count -= 1
922 if self._all_models_freeze_count == 0:
--> 923 self._recompute_all_models()
924
925 def _recompute_all_models(self):
/home/rgupta/anaconda2/lib/python2.7/site-packages/bokeh/document/document.pyc in _recompute_all_models(self)
929 new_all_models_set = set()
930 for r in self.roots:
--> 931 new_all_models_set = new_all_models_set.union(r.references())
932 old_all_models_set = set(self._all_models.values())
933 to_detach = old_all_models_set - new_all_models_set
AttributeError: 'NoneType' object has no attribute 'references'
Кажется, что это происходит только от функции show()
, но в то же время, если я передаю components()
, я получаю свой вывод.
Ниже приведен код вместе с фрагментом данных:
def Show_NameBased_Chart(in_dict):
source = ColumnDataSource(
data=dict(
Count = [val.get('size') for val in in_dict.values()],
# Unique_guests = Transaction_data[Transaction_data.chain_id == CID]\
# .groupby('merchant_id').user_id.nunique().tolist(),
Sales = [val.get('amount_spent') for val in in_dict.values()],
ID = [val for val in in_dict.keys()],
# Name = Transaction_data[Transaction_data.chain_id == CID]\
# .groupby('name').sum().index.astype(str).tolist(),
AVG = [val.get('avg') for val in in_dict.values()],
))
ID = [val for val in in_dict.keys()]
# Name = Transaction_data[Transaction_data.chain_id == CID]\
# .groupby('name').sum().index.astype(str).tolist()
# Label = Transaction_data[Transaction_data.chain_id == CID].location.unique()[0]
hover = HoverTool(tooltips=
# # ("(x,y)", "(@lat, @lon)"),
# ("Merch_ID", "@ID"),
# ('Revenue','Rs @Sales{0,0.000}'),
# ("Visits","@Count"),
# ('Avg Val/Tr','@AVG'),
# ('Mode','@Mode'),
# ("Unique_Visitors", "@Unique_guests")
"""
<div>
<div>
<span style="font-size: 10px;">Merch_Id:</span>
<span style="font-size: 15px; font-weight: bold;">@ID</span>
<div>
<div>
<span style="font-size: 10px;">Revenue:</span>
<span style= font-size:15px; font-weight: bold;>₹</span>
<span style="font-size: 15px; font-weight: bold;">@Sales{0,0.000}</span>
<div>
</div>
"""
)
p = figure(y_range= ID)
# p.background_fill_color = None
# p.background_fill_alpha = None
# labels = LabelSet(x='Count', y='ID', text='Count', level='glyph',
# y_offset=5, render_mode='canvas',source=source)
p.add_tools(hover)
p.grid.grid_line_color = None
p.xaxis.visible = None
p.yaxis.axis_line_color = None
p.xaxis.axis_line_color = None
p.xaxis.major_tick_line_color = None
p.xaxis.minor_tick_line_color = None
p.outline_line_alpha = 0.2
H_1= HBar(y='ID',right='Sales',height = 0.5,fill_color="#6C69EB")
# H_2 = HBar(y='ID',right='Sales',height = 0.5)
p.add_glyph(source, H_1)
# p_2 = p.add_glyph(source, H_2)
# p.add_layout(labels)
show(p)
in_dict = {u'1009': {u'Avg': 408.1859554880508,
u'amount_spent': 185851,
u'size': 444,
u'users': [216765,
632270,
416138,
267154,
220339,
346041,
657993,
658316,
576653,
658567,
658406,
658546]},
u'1056': {u'Avg': 436.19081688035646,
u'amount_spent': 87690,
u'size': 311,
u'users': [213761,
647666,
639524,
562168,
164913,
645767]},
u'1103': {u'Avg': 169.83717357910908,
u'amount_spent': 12734,
u'size': 69,
u'users': [370590,
353842,
617525,
339285,
658440]},
u'1105': {u'Avg': 260.63440860215053,
u'amount_spent': 15814,
u'size': 56,
u'users': [187569,
575770,
91651,
19981,
8966,
19863
]}
Я не могу найти никакой очевидной причины, почему это происходит.Используя функцию компонентов, я получаю свои script
, div
;который я могу построить.