Bokeh-plots-with-glyphs
ボケ-グリフ付きのプロット
プロットは通常、*線、円、四角形*などの1つ以上の幾何学的形状で構成されます。 これらの図形には、対応するデータのセットに関する視覚的な情報があります。 ボケの用語では、これらの幾何学的な形を「字形」と呼びます。 * bokeh.plottingインターフェイス*を使用して作成されたボケプロットは、ツールとスタイルのデフォルトセットを使用します。 ただし、使用可能なプロットツールを使用してスタイルをカスタマイズすることは可能です。
プロットの種類
グリフを使用して作成されたさまざまなタイプのプロットは以下のとおりです-
ラインプロット
このタイプのプロットは、x軸とy軸に沿った点の動きを線の形で視覚化するのに役立ちます。 時系列分析を実行するために使用されます。
バープロット
これは通常、データセット内の特定の列またはフィールドの各カテゴリの数を示すのに役立ちます。
パッチプロット
このプロットは、特定の色合いの点の領域を示しています。 このタイプのプロットは、同じデータセット内の異なるグループを区別するために使用されます。
散布図
このタイプのプロットは、2つの変数間の関係を視覚化し、それらの間の相関の強さを示すために使用されます。
Figureクラスの適切なメソッドを呼び出すことにより、異なるグリフプロットが形成されます。 図オブジェクトは、次のコンストラクタによって取得されます-
from bokeh.plotting import figure
figure(**kwargs)
Figureオブジェクトは、さまざまなキーワード引数でカスタマイズできます。
Sr.No | Title | Set the title for the plot |
---|---|---|
1 | x_axis_label | Set title of x axis |
2 | y_axis_label | Set title for y axis |
3 | plot_width | Set width of figure |
4 | plot_height | Set height of figure |
ラインプロット
Figureオブジェクトの* line()メソッド*は、線のグリフをボケの図に追加します。 線形関係を示すには、データ配列としてxパラメータとyパラメータが必要です。
from bokeh.plotting import figure, show
fig = figure()
fig.line(x,y)
show(fig)
次のコードは、Pythonリストオブジェクトの形式で2つの値のセット間の単純なラインプロットをレンダリングします-
from bokeh.plotting import figure, output_file, show
x = [1,2,3,4,5]
y = [2,4,6,8,10]
output_file('linel')
fig = figure(title = 'Line Plot example', x_axis_label = 'x', y_axis_label = 'y')
fig.line(x,y)
show(fig)
出力
バープロット
figureオブジェクトには、棒グラフを作成するための2つの異なるメソッドがあります。
hbar()
棒はプロット幅全体に水平に表示されます。 * hbar()メソッド*には次のパラメータがあります-
Sr.No | y | The y coordinates of the centers of the horizontal bars. |
---|---|---|
1 | height | The heights of the vertical bars. |
2 | right | The x coordinates of the right edges. |
3 | left | The x coordinates of the left edges. |
以下のコードは、ボケを使用した*水平バー*の例です。
from bokeh.plotting import figure, output_file, show
fig = figure(plot_width = 400, plot_height = 200)
fig.hbar(y = [2,4,6], height = 1, left = 0, right = [1,2,3], color = "Cyan")
output_file('barl')
show(fig)
出力
vbar()
バーは、プロットの高さ全体に垂直に表示されます。 * vbar()メソッド*には次のパラメータがあります-
Sr.No | x | The x-coordinates of the centers of the vertical bars. |
---|---|---|
1 | width | The widths of the vertical bars. |
2 | top | The y-coordinates of the top edges. |
3 | bottom | The y-coordinates of the bottom edges. |
次のコードは*縦棒グラフ*を表示します-
from bokeh.plotting import figure, output_file, show
fig = figure(plot_width = 200, plot_height = 400)
fig.vbar(x = [1,2,3], width = 0.5, bottom = 0, top = [2,4,6], color = "Cyan")
output_file('barl')
show(fig)
出力
パッチプロット
スペースの領域を特定の色で陰影付けして、同様のプロパティを持つ領域またはグループを示すプロットは、ボケではパッチプロットと呼ばれます。 この目的のために、Figureオブジェクトにはpatch()メソッドとpatch()メソッドがあります。
パッチ()
このメソッドは、与えられた図にパッチグリフを追加します。 このメソッドには次の引数があります-
1 | x | The x-coordinates for the points of the patch. |
2 | y | The y-coordinates for the points of the patch. |
簡単な*パッチプロット*は、次のPythonコードによって得られます-
from bokeh.plotting import figure, output_file, show
p = figure(plot_width = 300, plot_height = 300)
p.patch(x = [1, 3,2,4], y = [2,3,5,7], color = "green")
output_file('patchl')
show(p)
出力
パッチ()
このメソッドは、複数のポリゴンパッチを描画するために使用されます。 それは次の引数が必要です-
1 | xs | The x-coordinates for all the patches, given as a “list of lists”. |
2 | ys | The y-coordinates for all the patches, given as a “list of lists”. |
patch()メソッドの例として、次のコードを実行します-
from bokeh.plotting import figure, output_file, show
xs = [[ys = [[6,4,2], [3,6,7], [2,4,7,8]]
fig = figure()
fig.patches(xs, ys, fill_color = ['red', 'blue', 'black'], line_color = 'white')
output_file('patch_plotl')
show(fig)
出力
散布マーカー
散布図は、2つの変数間の二変量関係を決定するために非常によく使用されます。 強化されたインタラクティブ機能は、ボケを使用してそれらに追加されます。 散布図は、Figureオブジェクトのscatter()メソッドを呼び出すことによって取得されます。 それは次のパラメータを使用します-
1 | x | values or field names of center x coordinates |
2 | y | values or field names of center y coordinates |
3 | size | values or field names of sizes in screen units |
4 | marker | values or field names of marker types |
5 | color | set fill and line color |
以下のマーカータイプ定数がBokehで定義されています:−
- アスタリスク
- サークル
- サークルクロス
- CircleX
- クロス
- Dash
- ダイヤモンド
- ダイヤモンドクロス
- Hex
- 逆三角形
- 平方
- SquareCross
- SquareX
- 三角形
- X
次のPythonコードは、円マーク付きの散布図を生成します。
from bokeh.plotting import figure, output_file, show
fig = figure()
fig.scatter([1, 4, 3, 2, 5], [6, 5, 2, 4, 7], marker = "circle", size = 20, fill_color = "grey")
output_file('scatterl')
show(fig)