為你的儲蓄加上註解
過去 30 週你努力為第一台車累積儲蓄。不過,圖上需要補充一些情境,來說明一次儲蓄的下滑,以及之後每兩週累積金額的大幅增加。
你的任務是替每週儲蓄餘額的長條圖加上註解,並在圖上加入兩個關鍵註解,說明發生了什麼事。
已替你使用 savings DataFrame(x 為 Week)建立了一個圖形物件 fig。
本練習屬於課程
Python 的 Plotly 資料視覺化入門
練習說明
- 在第 10 週(儲蓄 400)建立
loss_annotation,文字為"Urgent House Repairs"。 - 在第 18 週(儲蓄 2500)建立
gain_annotation,文字為"New Job"。 - 使用
update_layout()將兩個註解一併加入fig。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create the first annotation
loss_annotation = dict(
x=____, y=____, text="____",
font=dict(color="black"), showarrow=True, arrowhead=4
)
# Create the second annotation
gain_annotation = dict(
x=____, y=____, text="____",
font=dict(color="black"), showarrow=True, arrowhead=4,
)
# Add annotations to the figure
fig.update_layout(annotations=[____, ____])
# Show the plot
fig.show()