開始使用免費開始

依時間與日類型的銷售額

你合作的烘焙坊正在考慮調整營業時間。因此,他們請你製作一個視覺化圖表,分別顯示平日與週末在一天各時段的銷售資訊。

bakeryday_time 欄位包含 4 個值:"Morning""Afternoon""Evening""Night"

資料集的 day_type 欄位也包含 "Weekend""Weekday" 兩種值。

你將繪製一個群組長條圖,同時依時間與日類型呈現銷售額。FactorRange 已為你匯入。

bakery 資料集已依 day_timeday_type 分組並儲存為 grouped_bakery,且已預先載入。包含這兩個欄位所有組合的 tuple 已儲存為 factors,也已預先載入。

本練習屬於課程

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

檢視課程

練習說明

  • 建立 fig,將 x_range 設為呼叫 FactorRange() 並傳入 *factors,y 軸標籤指定為 "Sales",標題設為 "Sales by type of day"
  • factors 加入長條圖形(bar glyph),其頂端數值使用 grouped_bakery["sales"],並將長條寬度設為 90%。
  • 將標題字型大小更新為 "25px"
  • 將標題格式改為置中對齊。

動手互動練習

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

# Create figure
fig = ____

# Create bar glyphs
____
fig.yaxis[0].formatter = NumeralTickFormatter(format="$0,0")

# Update title text size
fig.____.____ = "____"

# Update title alignment
fig.____.____ = "____"

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