Data Visualization & DataBase
Bokeh - Web visualization
Dan-k
2020. 1. 17. 15:58
반응형
bokeh에서 multiple plot에 마우스를 갖다대면 정보가 나오게 하는 방법!!!
바로!
HoverTool 이다.
이 툴을 이용하면 표시하길 원하는 tooltips를 추가하고, 각 plot별로 렌터링해서 표현해줄 수 있다.
예를 들면 두개의 plot이 섞여 있을때 각기 다른 정보를 보여줄수 있다!!!
코드를 보자
HoverTool 의 argument로 renderers 라는 것에 plot별 tooltips을 넣어줄수 있다!!!!
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource,HoverTool
from bokeh.layouts import row, column, gridplot
## interactive annotation을 위해 Datetime이 str 형태로 저장된 정보 저장스
temp_df['when'] = [x.strftime("%Y-%m-%d %H:%M:%S") for x in temp_df['Datetime']]
source = ColumnDataSource(temp_df)
fig_lst = []
for i in ['origin','trend','seasonal','resid'] :
fig = figure(x_axis_type="datetime")
plot1 = fig.line('Datetime',i, source=source)
tooltips1 = [
('Datetime','@when'),
('Value','@{}'.format(i)),
('part',i)
]
fig.add_tools(HoverTool(renderers=[plot1],tooltips=tooltips1,formatters={'Datetime':'datetime'}))
fig.title.text = '{}_{}_{}'.format(worldno, feature,i.upper())
fig.xaxis.axis_label = 'TimeStamp'
fig.yaxis.axis_label = 'Values'
if i in ['origin','resid']:
plot2 = fig.circle('Datetime', 'anomaly_1',source=source,color="green",alpha=0.5,size=5)
plot3 = fig.circle('Datetime', 'anomaly_2',source=source,color="orange",alpha=0.5,size=7)
plot4 = fig.circle('Datetime', 'anomaly_3',source=source,color="red",alpha=0.7,size=10)
tooltips2 = [
('Datetime','@when'),
('Value','@{}'.format(i)),
('Threshold','@threshold')
]
fig.add_tools(HoverTool(renderers=[plot2,plot3,plot4],tooltips=tooltips2,formatters={'Datetime':'datetime'}))
fig_lst.append(fig)
grid = gridplot(fig_lst, ncols=1, plot_width=1400, plot_height=200)
return grid
그러면...그림에
이렇게 line plot interactive annotation 따로
scatter plot interactive annotation 따로 나오게 된다
bokeh를 이용한 시각화....너무 무궁무진하다..
아래 링크 참고 고고고
https://docs.bokeh.org/en/latest/docs/user_guide/plotting.html
docs.bokeh.org
728x90
반응형
LIST