# リスト7.13.1:ツールバーを下側に配置
from bokeh.plotting import figure, output_notebook, show
output_notebook()
p = figure(plot_width=250, plot_height=250, toolbar_location="below")
show(p)
# リスト7.13.2:ツールバーを左側に配置
from bokeh.charts import Bar
p = Bar([1, 2, 3], plot_width=300, plot_height=250, toolbar_location="left")
show(p)
# リスト7.13.3:ツールバーの重なりを修正
p = Bar(
[1, 2, 3],
plot_width=250,
plot_height=250,
toolbar_location="left",
toolbar_sticky=False,
)
show(p)
# リスト7.13.4:指定したツールをツールバーに表示
p = figure(plot_width=250, plot_height=250, tools=["crosshair", "wheel_zoom", "reset"])
p.circle([1, 2, 3], [1, 2, 3], size=40)
show(p)
# リスト7.13.5:アクティブ状態を変更
p = figure(
plot_width=250, plot_height=250, active_drag=None, active_scroll="wheel_zoom"
)
p.circle([1, 2, 3], [1, 2, 3], size=40)
show(p)
# リスト7.13.6:Hoverツールを表示
p = figure(plot_width=300, plot_height=300, tools="hover")
p.circle([1, 2, 3], [1, 2, 3])
show(p)
# リスト7.13.7:Hoverツールのカスタマイズ
from bokeh.models import HoverTool
import os
import pandas as pd
base_url = (
"https://raw.githubusercontent.com/practical-jupyter/sample-data/master/anime/"
)
anime_master_csv = os.path.join(base_url, "anime_master.csv")
df = pd.read_csv(anime_master_csv)
hover = HoverTool(
tooltips=[
("index", "$index"),
("(x, y)", "($sx, $sy)"),
("name", "@name"),
("genre", "@genre"),
("members", "@members{0,0}"), # カンマ区切り
("rating", "@rating"),
]
)
p = figure(tools=[hover])
p.circle("members", "rating", source=df)
show(p)