銷售額隨時間的變化
房仲業者現在請你檢視房市活動,將總銷售額隨時間的變化視覺化。melb DataFrame 已依 date 分組,這次以 price 欄位的總和計算總銷售額,並儲存為 melb_sales:
melb_sales = melb.groupby("date", as_index=False)["price"].sum()
source 已由 melb_sales 建立並預先載入。你的任務是為圖形設定合適的格式,使用有意義的座標軸,讓人能從視覺化中獲得洞見。
本練習屬於課程
使用 Bokeh 製作互動式資料視覺化
練習說明
- 匯入將座標軸標籤變更為
datetime與numeric格式所需的類別。 - 在圖上加入線圖元,將 y 指定為
"price"、x 指定為"date"(來源為source)。 - 將 x 軸格式更新為月份顯示 3 個字母、年份顯示 4 位數字。
- 將 y 軸格式設為
"$0a",以百萬美元顯示。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import the second formatter
from bokeh.models import ____, ____
fig = figure(x_axis_label="Date", y_axis_label="Sales")
# Add line glyphs
fig.line(____)
# Format the x-axis format
fig.____[____].____ = ____(months="____")
# Format the y-axis format
fig.____[____].____ = ____(format="____")
output_file(filename="melbourne_sales.html")
show(fig)