# リスト7.8.1:高レベルのインタフェースによる軸範囲の設定
from bokeh.charts import Line, output_notebook, show
from bokeh.models import Range1d
output_notebook()
p = Line([1, 2], plot_width=200, plot_height=200)
p.x_range = Range1d(0, 10)
p.y_range = Range1d(0, 10)
show(p)
# リスト7.8.2:中レベルのインタフェースによる軸範囲の設定
from bokeh.plotting import figure
p = figure(x_range=(0, 10), y_range=(0, 10), plot_width=200, plot_height=200)
p.line([1, 2], [1, 2])
show(p)
# リスト7.8.3:FactorRangeクラスによる設定
from bokeh.models import FactorRange
p = figure(y_range=FactorRange("a", "b"), plot_width=200, plot_height=200)
p.line([1, 2], [1, 2])
show(p)
# リスト7.8.4:y_rangeにリストを渡す場合
p = figure(y_range=(["a", "b"]), plot_width=200, plot_height=200)
p.line([1, 2], [1, 2])
show(p)
# リスト7.8.5:時系列軸の設定
import os
import pandas as pd
base_url = (
"https://raw.githubusercontent.com/practical-jupyter/sample-data/master/anime/"
)
anime_stock_price = os.path.join(base_url, "anime_stock_price.csv")
df = pd.read_csv(anime_stock_price, parse_dates=["Date"], index_col=0)
p = figure(x_axis_type="datetime", plot_width=400, plot_height=200)
p.line(df.index, df["TOEI ANIMATION"])
show(p)
# リスト7.8.6:対数軸の設定
x = range(10)
y = [i ** 10 for i in x]
p = figure(y_axis_type="log", plot_width=200, plot_height=200)
p.line(x, y)
show(p)
# リスト7.8.7:2軸の設定
from bokeh.models import LinearAxis, Range1d
p = figure(y_range=(0, 5), plot_width=200, plot_height=200) # ①
p.extra_y_ranges = {"y2": Range1d(0, 100)} # ②③④
p.add_layout(LinearAxis(y_range_name="y2"), "left") # ⑤⑥
p.line([1, 2], [1, 3], color="red", legend="1軸目")
p.line([1, 2], [10, 80], y_range_name="y2", legend="2軸目") # ⑦
p.legend.location = "top_left"
p.legend.background_fill_alpha = 0
show(p)