成長地點下拉選單
澳洲政府想了解哪些地方政府區(LGA)近年人口成長強勁,以協助規劃基礎建設專案。
他們提供了 2018 年到 2019 年期間,人口成長百分比排名前 5 名的 LGA 資料,並請你將其視覺化。不過,他們希望能選擇特定州別,或一次查看所有州別。
在這個練習中,你需要建立一個長條圖,並加入下拉選單,以在不同州之間切換,或一次顯示所有州。
你已經有一個 pop_growth 的 DataFrame,以及一個已為你建立好的 go.Figure() 物件可使用。
本練習屬於課程
Python 的 Plotly 資料視覺化入門
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create the figure
fig = go.Figure()
# Loop through the states
for state in ['NSW', 'QLD', 'VIC']:
# Subset the DataFrame
df = pop_growth[pop_growth.State == state]
# Add a trace for each state subset
fig.add_trace(px.bar(df, x='Local Government Area', y='Change %').data[0])
# Create the buttons
dropdown_buttons = [
{'label': "ALL", 'method': "____", 'args': [{"visible": [True, True, True]}, {"title": "ALL"}]},
{'label': "NSW", 'method': "____", 'args': [{"visible": [____, ____, ____]}, {"title": "NSW"}]},
{'label': "QLD", 'method': "____", 'args': [{"visible": [____, ____, ____]}, {"title": "QLD"}]},
{'label': "VIC", 'method': "____", 'args': [{"visible": [____, ____, ____]}, {"title": "VIC"}]},
]