開始使用免費開始

一天中不同時段的銷售商品數

烘焙坊想要查看一天中不同時段賣出多少商品。

已為你設定並預先載入圖表 fig,其中包含 HoverTool,可顯示時段、品項名稱,以及銷售數量。

你需要替圖例加上標題,讓利害關係人理解其意義;再把圖例移開,避免遮擋觀察值;並調整圖例設定,讓使用者點擊後能隱藏對應的觀察值。

本練習屬於課程

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

檢視課程

練習說明

  • 在圖例中加入標題 "Time of Day"
  • 將圖例移到左上角。
  • 讓圖例具備互動性,點擊圖例標籤時可隱藏對應的觀察值。

動手互動練習

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

fig = figure(x_axis_label="Count of Products Sold", y_axis_label="Sales", title="Bakery Product Sales", tooltips=TOOLTIPS)
fig.circle(x="count", y="sales", source=morning, line_color="red", size=12, fill_alpha=0.4, legend_label="Morning")
fig.circle(x="count", y="sales", source=afternoon, fill_color="purple", size=10, fill_alpha=0.6, legend_label="Afternoon")
fig.circle(x="count", y="sales", source=evening, fill_color="yellow", size=8, fill_alpha=0.6, legend_label="Evening")

# Add legend title
fig.____.____ = "____"

# Move the legend
fig.____.____ = "____"

# Make the legend interactive
fig.____.____ = "____"
fig.yaxis[0].formatter = NumeralTickFormatter(format="$0.00")
output_file("Sales_by_time_of_day")
show(fig)
編輯並執行程式碼