2016-09-10 49 views
0

bar charthorizontal lineにレンダリングすると、どの値(バーで表される)が特定のしきい値(水平線)を超えているかがわかります。私のデータはPandasのデータフレームで表されます。Bokehのボックスプロットに水平線( `Span`)を追加するには?

from bokeh.plotting import figure, output_file, show 
from bokeh.charts import Bar 
from bokeh.models import Span 
from bokeh.io import save 
from pandas import DataFrame 

output_file('tmp_file') 

p = figure(plot_width=800, plot_height=600) 

rows = [(1,'2004-01-15', 10), (2,'2004-02-21', 15)] 
headers = ['id', 'date', 'value'] 

df = DataFrame.from_records(rows, columns=headers) 
bar = Bar(df, 'date', values='value', agg='mean') 

treshold = 12 

hline = Span(location=treshold, dimension='width', line_color='red', line_width=3) 

p.renderers.extend([hline, bar]) 
save(p) 

Exeptionは私が取得:

File "/usr/lib/python3.4/site-packages/bokeh/core/properties.py", line 1056, in validate 
    raise ValueError("expected an element of %s, got seq with invalid items %r" % (self, invalid)) 
ValueError: expected an element of List(Instance(Renderer)), got seq with invalid items [<bokeh.charts.chart.Chart object at 0x7fa0a4534f28>] 

答えて

2

[OK]を、私はそれを考え出した...

from bokeh.charts import Bar 
from bokeh.models import Span 
from bokeh.io import save, output_file, show 
from pandas import DataFrame 
output_file('tmp_file') 

rows = [(1,'2004-01-15', 10), (2,'2004-02-21', 15)] 
headers = ['id', 'date', 'value'] 

df = DataFrame.from_records(rows, columns=headers) 
bar = Bar(df, 'date', values='value', agg='mean') 

treshold = 12 

hline = Span(location=treshold, dimension='width', line_color='red', line_width=3) 

bar.renderers.extend([hline]) 
save(bar) 
関連する問題