CommencerCommencer gratuitement

Growth locations dropdown

The Australian Government wants to understand which Local Government Areas (LGAs) have had recent strong population growth to assist in planning infrastructure projects.

They have provided you with some data on the top 5 LGAs by the percentage of population increase (from 2018 to 2019) and have asked if you can visualize it. However, they want to be able to select a certain state or see everything at once.

In this exercise, you are tasked with creating a bar chart of this data with a drop-down menu to switch between different states and see all states at once.

You have a pop_growth DataFrame available, and a go.Figure() object will be set up for you.

Cet exercice fait partie du cours

Introduction to Data Visualization with Plotly in Python

Afficher le cours

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# 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"}]},
]
Modifier et exécuter le code