Bokeh-getting-started

提供:Dev Guides
移動先:案内検索

ボケ-はじめに

2つのnumpy配列の間に単純なラインプロットを作成するのは非常に簡単です。 まず、 bokeh.plotting モジュールから次の関数をインポートします-

from bokeh.plotting import figure, output_file, show
  • figure()*関数は、プロット用の新しい図を作成します。
  • output_file()*関数は、出力を格納するHTMLファイルを指定するために使用されます。
  • show()*関数は、ノートブックのブラウザでボケの図を表示します。

次に、2つの派手な配列を設定します。2番目の配列は最初の正弦値です。

import numpy as np
import math
x = np.arange(0, math.pi*2, 0.05)
y = np.sin(x)

ボケ図形オブジェクトを取得するには、以下のようにタイトルとx軸とy軸のラベルを指定します-

p = figure(title = "sine wave example", x_axis_label = 'x', y_axis_label = 'y')

図オブジェクトには、線グリフを図に追加するline()メソッドが含まれています。 x軸とy軸のデータ系列が必要です。

p.line(x, y, legend = "sine", line_width = 2)

最後に、出力ファイルを設定し、show()関数を呼び出します。

output_file("sinel")
show(p)

これにより、ラインプロットが「sinel」でレンダリングされ、ブラウザに表示されます。

完全なコードとその出力は次のとおりです

from bokeh.plotting import figure, output_file, show
import numpy as np
import math
x = np.arange(0, math.pi*2, 0.05)
y = np.sin(x)
output_file("sinel")
p = figure(title = "sine wave example", x_axis_label = 'x', y_axis_label = 'y')
p.line(x, y, legend = "sine", line_width = 2)
show(p)

ブラウザでの出力

モデルを作成