Aan de slagGa gratis aan de slag

GDP vs. life expectancy legend

The United Nations has contacted you to help them understand and visualize their data. They have been playing with various visualization tools but can't seem to find the design that they want.

They want to understand the relationship (if it exists) between GDP and life expectancy and have gathered data on over 200 countries to analyze. However, their initial efforts have confused stakeholders, and they need a clear legend below the plot to help viewers understand it.

Your task is to create a scatterplot using the provided life_gdp DataFrame and style and position the legend as requested.

Deze oefening maakt deel uit van de cursus

Introduction to Data Visualization with Plotly in Python

Cursus bekijken

Oefeninstructies

  • Create a scatterplot using the life_gdp DataFrame, setting the x-axis to be Life expectancy, the y-axis to be GDP Per Capita.
  • Create a legend dictionary positioned 20% along the x-axis and 95% up the y-axis.
  • Update the layout of your scatterplot to show the legend you just created!

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Create the scatterplot
fig = px.scatter(
        data_frame=____, 
        x="____", 
        y="____",
  		color="Continent")

# Create legend dictionary
my_legend = dict(x=0.2, y=____)

# Update the figure
fig.update_layout(showlegend=____, legend=my_legend)

# Show the plot
fig.show()
Code bewerken en uitvoeren