開始使用免費開始

色彩、圖例與佈景主題

你的第一個任務是為房仲製作一個視覺化,呈現房屋興建年份與土地總面積之間的關係,並考量墨爾本北部與南部地區之間的差異。你決定在這個圖上使用 Bokeh 的自訂佈景主題。

已根據房屋所在的 region 建立了 melb 的兩個子集,northsouth,如下所示:

north = melb.loc[melb["region"] == "Northern"]
south = melb.loc[melb["region"] == "Southern"]

一個 figure,fig,已為你預先載入。你將更新佈景主題,並為每個地區以不同色彩加入圓點圖元。接著加入一個 legend_label,讓它們更容易區分。

本練習屬於課程

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

檢視課程

練習說明

  • 匯入 curdoc
  • 將佈景主題更新為 "contrast"
  • north 加入圓點圖元,xy 分別代表 year_builtland_areacolor 設為 "yellow"legend_label 設為 "North"
  • 針對 south 重複上述步驟,color 設為 "red"legend_label 設為 "South"

動手互動練習

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

# Import curdoc
from ____.____ import ____

# Change theme to contrast
____().____ = "____"
fig = figure(x_axis_label="Year Built", y_axis_label="Land Area (Meters Squared)")

# Add north circle glyphs
fig.circle(x=north["____"], y=north["____"], color="____", legend_label="____")

# Add south circle glyphs
fig.____(____=____, ____=____, ____="____", legend_label="____")

output_file(filename="north_vs_south.html")
show(fig)
編輯並執行程式碼