2017-09-30 3 views
0

상단에 오류 막대가있는 막 대형 차트를 만들려고합니다. 나는이보기를 생성하기 위해 다음의 answer을 보았다. 내 오류 코드는 p.line(y_err_x, y_err_y, color="black") 일 때까지 x 축 인덱스로 인해 다음과 같은 오류가 발생합니다. Unable to get property 'A' of undefined or null referenceBokeh의 막 대형 차트 위에 오류 막대 추가

적절한 사용법은 무엇입니까? 미리 감사드립니다!

from bokeh.io import show, output_notebook 
from bokeh.models import ColumnDataSource 
from bokeh.plotting import figure 
from bokeh.transform import factor_cmap 

output_notebook() 
groups= ['A', 'B', 'C', 'D'] 
counts = [5, 3, 4, 2] 
yerr = [1,2,3,4] 

source = ColumnDataSource(data=dict(groups=groups, counts=counts)) 

p = figure(x_range=groups, plot_height=350, toolbar_location=None, title="Values") 
p.vbar(x='groups', top='counts', width=0.9, source=source, legend="groups", 
     line_color='white', fill_color=factor_cmap('groups', palette=["#962980","#295f96","#29966c","#968529"], 
                factors=groups)) 

y_err_x = [] 
y_err_y = [] 
for px, py, err in zip(groups, counts, yerr): 
    y_err_x.append((px, px)) 
    y_err_y.append((py - err, py + err)) 

p.line(y_err_x, y_err_y, color="black") 

p.xgrid.grid_line_color = None 
p.legend.orientation = "horizontal" 
p.legend.location = "top_center" 

show(p) 

답변

1

그 대답은 더 이상 필요하지 않습니다.

from bokeh.io import show, output_file 
from bokeh.models import ColumnDataSource, Whisker 
from bokeh.plotting import figure 
from bokeh.transform import factor_cmap 

output_file("error.html") 

groups= ['A', 'B', 'C', 'D'] 
counts = [5, 3, 4, 2] 
error = [0.8, 0.4, 0.4, 0.3] 
upper = [x+e for x,e in zip(counts, error) ] 
lower = [x-e for x,e in zip(counts, error) ] 

source = ColumnDataSource(data=dict(groups=groups, counts=counts, upper=upper, lower=lower)) 

p = figure(x_range=groups, plot_height=350, toolbar_location=None, title="Values", y_range=(0,7)) 
p.vbar(x='groups', top='counts', width=0.9, source=source, legend="groups", 
     line_color='white', fill_color=factor_cmap('groups', palette=["#962980","#295f96","#29966c","#968529"], 
                factors=groups)) 

p.add_layout(
    Whisker(source=source, base="groups", upper="upper", lower="lower", level="overlay") 
) 

p.xgrid.grid_line_color = None 
p.legend.orientation = "horizontal" 
p.legend.location = "top_center" 

show(p) 

enter image description here

:

https://bokeh.pydata.org/en/latest/docs/user_guide/annotations.html#whiskers

하고 여기에

https://bokeh.pydata.org/en/latest/docs/user_guide/annotations.html#bands

이 완벽한 예입니다 : 오류 주석이 이제 보케에 내장되어, 설명서를 참조하십시오
관련 문제