如何在 Bokeh 中視覺化包含多個補丁的補丁圖?


Bokeh 是一個用於資料視覺化的 Python 包。它是一個開源專案。Bokeh 使用 HTML 和 JavaScript 渲染其繪圖。這表明它在處理基於 Web 的儀表板時非常有用。

Bokeh 可以輕鬆地與 NumPy、Pandas 和其他 Python 包結合使用。它可用於生成互動式圖表、儀表板等。它有助於有效地向受眾傳達定量見解。

Matplotlib 和 Seaborn 生成靜態圖表,而 Bokeh 生成互動式圖表。這意味著當用戶與這些圖表互動時,它們會相應地發生變化。

圖表可以嵌入為 Flask 或 Django 啟用的 Web 應用程式的輸出。Jupyter notebook 也可以用於渲染這些圖表。

Bokeh 的依賴項 -

Numpy
Pillow
Jinja2
Packaging
Pyyaml
Six
Tornado
Python−dateutil

在 Windows 命令提示符下安裝 Bokeh

pip3 install bokeh

在 Anaconda 提示符下安裝 Bokeh

conda install bokeh

示例

from bokeh.plotting import figure, output_file, show
xs = [[5, 6, 9], [2,3,6], [4, 3, 7, 1]]
ys = [[6, 5, 8], [3,0,8], [2, 3, 6, 8]]
fig = figure(plot_width = 400, plot_height = 200)
fig.patches(xs, ys, fill_color = ['red', 'blue', 'green'], line_color = 'white')
output_file('patchplot.html')
show(fig)

輸出

解釋

  • 匯入併為所需的包設定別名。

  • 呼叫 figure 函式。

  • 呼叫 'output_file' 函式以指定將生成的 html 檔案的名稱。

  • 資料定義為列表的列表。

  • 圖表的寬度和高度在 'figure' 函式中定義。

  • 呼叫 Bokeh 中的 'patches' 函式。

  • 使用 'show' 函式顯示圖表。

更新於:2021 年 1 月 18 日

170 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告