開始使用免費開始

更有溫度的長條圖

你替一間證券交易公司做了長條圖後,他們覺得目前產生的資料與圖表太缺乏人情味。

他們要求在你最近建立的公司營收長條圖上,加上一段正向的訊息。

你剛好有個好主意——祝觀看者有美好的一天,並帶入今天是星期幾!

已為你準備好一個 fig 長條圖,需要時可以 show()print() 來回想它的樣子。

本練習屬於課程

Python 的 Plotly 資料視覺化入門

檢視課程

練習說明

  • 將註解放在 x 軸的中間、y 軸的 95% 高度位置。
  • 為相對定位設定正確的 xrefyref 值。
  • 使用 update_layout() 方法加入註解。

動手互動練習

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

# Get and format today's date
today = datetime.today().strftime("%A")

# Create the message_annotation
message_annotation = dict(
  # Set the correct coordinates
  x=____, y=____, xref="____", yref="____",
  # Set the format of the text and box
  text=f"Have a Happy {today} :)",
  font=dict(size=20, color="white"),
  bgcolor="rgb(237, 64, 200)", showarrow=False
)

# Update the figure layout and show
fig.update_layout(annotations=[____])
fig.show()
編輯並執行程式碼