概要
深層学習のlossのグラフを書くためにBokehを使ったところエラーが出た。
エラーの出たコード
import numpy as np from bokeh.plotting import figure, output_file, show, reset_output # 出力設定 reset_output() output_file("graph.html") TOOLTIPS = [ ("index", "$index"), ("(x,y)", "($x, $y)"), ] # グラフ設定 p = figure(tooltips=TOOLTIPS, title="sin, cosカーブ", x_axis_label="x", y_axis_label="y") # プロット p.line(x, y1, legend="sin") p.line(x, y2, legend="cos") # グラフ表示 show(p)
上記のコードをsample.py
として保存し、実行してみると
Traceback (most recent call last): File "error_sample.py", line 15, in <module> p = figure(tooltips=TOOLTIPS, title="sin, cosカーブ", x_axis_label="x", y_axis_label="y") (中略) AttributeError: unexpected attribute 'tooltips' to Figure, possible attributes are above, aspect_scale, background_fill_alpha, background_fill_color, below, border_fill_alpha, border_fill_color, css_classes, disabled, extra_x_ranges, extra_y_ranges, h_symmetry, height, hidpi, inner_height, inner_width, js_event_callbacks, js_property_callbacks, layout_height, layout_width, left, lod_factor, lod_interval, lod_threshold, lod_timeout, match_aspect, min_border, min_border_bottom, min_border_left, min_border_right, min_border_top, name, outline_line_alpha, outline_line_cap, outline_line_color, outline_line_dash, outline_line_dash_offset, outline_line_join, outline_line_width, output_backend, plot_height, plot_width, renderers, right, sizing_mode, subscribed_events, tags, title, title_location, toolbar, toolbar_location, toolbar_sticky, v_symmetry, width, x_range, x_scale, y_range or y_scale
解決策
こちらを参考にしてHoverTool
をimportしてtooltips
を定義した。
解決したコードは
import numpy as np from bokeh.plotting import figure, output_file, show, reset_output from bokeh.models import HoverTool # 出力設定 reset_output() output_file("graph.html") x = np.linspace(0, 10, 200) y1 = np.sin(x) y2 = np.cos(x) hover_tool = HoverTool( tooltips=[ ("index", "$index"), ("(x,y)", "($x, $y)") ], formatters={ "time": "datetime", }, mode='vline' ) # グラフ設定 p = figure( title="sin, cosカーブ", x_axis_label="x", y_axis_label="y", plot_width=1200, plot_height=800, # tools=hover_tool ) p.tools.append(hover_tool) # プロット p.line(x, y1, legend="sin") p.line(x, y2, legend="cos") # グラフ表示 show(p)