開始使用免費開始

為科學研究調整風格

既然你已經熟悉如何自訂圖表,現在就讓你的創意發揮吧!

在這個練習中,你會繼續與南極研究團隊合作,協助他們探索並理解所蒐集到的企鵝資料。

他們希望了解不同物種之間的鰭長差異。時間有限,所以你認為用 plotly.express 製作一個快速視覺化就很合適。不過,他們也想對座標軸標題做一些特定的自訂。

你手邊有一個 penguins 的 DataFrame。

本練習屬於課程

Python 的 Plotly 資料視覺化入門

檢視課程

練習說明

  • penguins DataFrame 建立一個 plotly 長條圖,圖表標題為 "Flipper Length (mm) by Species",x 軸使用 "spec",y 軸使用 "av_flip_length"
  • 使用 .update_layout() 方法,將 xaxisyaxis 的文字分別改為 "Species""Average Flipper Length (mm)"

動手互動練習

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

# Create the plot
fig = px.bar(penguins, x="____", y="____", title="____", color="spec")

# Change the axis titles
fig.update_layout(
    xaxis=dict(title=dict(text="____")),
    yaxis=dict(title=dict(text="____"))
)

# Show the plot
fig.show()
編輯並執行程式碼