開始使用免費開始

依期間視覺化銷售額

你已經建立好 factors,現在要來繪製長條圖,將每月的銷售額依季分組呈現!

已為你預先載入 grouped_melb,這是一個 pandas DataFrame,每個月各一列,包含所屬的季與該月的總銷售額。此外,也已預先載入 factors,它是由每個季與月份配對所組成的 tuple 清單。

本練習屬於課程

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

檢視課程

練習說明

  • 匯入 NumeralTickFormatterFactorRange
  • 建立圖表,x 軸使用 FactorRange()factors,並將 y 軸標示為「"Sales"」。
  • 加入長條圖 glyph,將 x 設為 factorstop 設為 grouped_melb 的「"price"」欄位,width 設為 0.9
  • 將 x 軸標籤旋轉為 45 度。

動手互動練習

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

# Import NumeralTickFormatter and FactorRange
from ____.____ import ____, ____

# Create figure
fig = ____(x_range=____(____), ____="____")

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

# Rotate the x-axis labels
fig.____.____ = ____

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