貯金額に注釈を付ける
あなたは最初の車を買うために、この30週間でコツコツと貯金残高を増やしてきました。ただし、途中で貯金が減った理由や、その後2週間ごとに大きく増えた背景を説明するために、いくつかの補足情報が必要です。
あなたの課題は、週ごとの貯金残高の棒グラフに注釈を付け、何が起きたのかを説明する2つの重要な注釈を追加することです。
Week を x とする savings DataFrame を使って作成済みの図 fig が用意されています。
この演習はコースの一部です
Pythonで学ぶPlotlyによるデータ可視化入門
演習の手順
- 週10(貯金400)に、テキスト
"Urgent House Repairs"のloss_annotationを作成します。 - 週18(貯金2500)に、テキスト
"New Job"のgain_annotationを作成します。 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()