開始使用免費開始

使用 gridplot

房仲業者想檢視在墨爾本四個區域之間,房屋面積與價格的關係如何改變:

"Northern""Western""Eastern""Southern"

這正好可以用 gridplot,為每個區域各顯示一個子圖!

本練習屬於課程

使用 Bokeh 製作互動式資料視覺化

檢視課程

練習說明

  • 匯入 gridplot
  • melb 依指定區域篩選後建立 df
  • 完成程式碼,把圓形圖元加到 figx 代表建物面積欄位,y 代表價格,資料來源用 source,並將 legend_label 設為 region
  • 使用兩欄的格狀佈局來顯示這些子圖。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Import gridplot
from ____.____ import ____
plots = []

# Complete for loop to create plots
for region in ["Northern", "Western", "Southern", "Eastern"]:
  df = melb.loc[melb["region"] == ____]
  source = ColumnDataSource(data=df)
  fig = figure(x_axis_label="Building Area (Meters Squared)", y_axis_label="Price")
  fig.circle(x="____", y="____", source=____, legend_label=____)
  fig.yaxis[0].formatter = NumeralTickFormatter(format="$0a")
  plots.append(fig)

# Display plot
output_file(filename="gridplot.html")
show(____(____, ncols=____))
編輯並執行程式碼