使用 gridplot
房仲業者想檢視在墨爾本四個區域之間,房屋面積與價格的關係如何改變:
"Northern"、"Western"、"Eastern" 和 "Southern"。
這正好可以用 gridplot,為每個區域各顯示一個子圖!
本練習屬於課程
使用 Bokeh 製作互動式資料視覺化
練習說明
- 匯入
gridplot。 - 將
melb依指定區域篩選後建立df。 - 完成程式碼,把圓形圖元加到
fig,x代表建物面積欄位,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=____))