Data Visualization & DataBase
Bokeh interactive legend
Dan-k
2020. 2. 14. 17:52
반응형
Bokeh에서는 interactive legend라는 것이 있어
레전드에 표시된 대상들을 figure에 표시했다 숨겼다할 수 있는 기능이 있다.
코드는
아래와 같다
from bokeh.embed import components
from bokeh.plotting import figure
from bokeh.resources import INLINE
from bokeh.util.string import encode_utf8
from bokeh.models import ColumnDataSource, HoverTool, Legend, LegendItem
from bokeh.layouts import gridplot
plot2 = fig.circle('Datetime', 'anomaly_1', source=source, legend='level:1', color="green", alpha=0.5, size=7)
plot3 = fig.circle('Datetime', 'anomaly_2', source=source, legend='level:2', color="orange", alpha=0.5, size=8)
plot4 = fig.circle('Datetime', 'anomaly_3', source=source, legend='level:3', color="red", alpha=0.7, size=10)
tooltips2 = [
('Datetime', '@when'),
('Value', '@resid'),
('Threshold', '@threshold')
]
## legend option
fig.legend.orientation = "horizontal"
fig.legend.location = "top_left"
fig.legend.label_text_font_size = '10pt'
fig.legend.click_policy="hide"
fig.legend.background_fill_alpha = 0.5
fig.legend.padding = 2
fig.legend.margin = 3
fig.add_tools(
HoverTool(renderers=[plot2, plot3, plot4], tooltips=tooltips2, formatters={'Datetime': 'datetime'}))
bokeh는 legend 에서 클릭을 통해 그림에 표시/해제 할 수 있다.
bokeh에는 기능이 상당히 많아서...
찾아보면 유용한 것들이 참 많다.
Interactive Legends — Bokeh 1.4.0 documentation
Legends added to Bokeh plots can be made interactive so that clicking or tapping on the legend entries will hide or mute the corresponding glyph in a plot. These modes are activated by setting the click_policy property on a Legend to either "hide" or "mute
docs.bokeh.org
728x90
반응형
LIST