LoslegenKostenlos loslegen

Monthly temperatures layered

The Australian Bureau Of Meteorology has tasked you with helping them build some nice interactive plots for their website.

They want to look at both the daily temperature from January to July this year and smooth out all the data points with a nice trend line of the monthly average temperature.

This would be an excellent opportunity to layer two plots together to achieve the desired outcome.

You have been provided a temp_syd DataFrame containing the daily (max) temperature from January to July 2020. You also have a temp_syd_avg DataFrame containing each month's average daily (max) temperature.

Diese Übung ist Teil des Kurses

Introduction to Data Visualization with Plotly in Python

Kurs anzeigen

Anleitung zur Übung

  • Create a bar chart using temp_syd and save it as daily_temp_fig.
  • Create a line chart using temp_syd_avg and save it as monthly_avg_fig.
  • Combine both plots using the Figure() constructor.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Create a bar chart for daily temperatures
daily_temp_fig = px.____(temp_syd, 
    x='Date', y='Temp')

# Create a line chart for monthly averages
monthly_avg_fig = px.____(
    temp_syd_avg, x='Date', y='Average', color_discrete_sequence=['red'])

# Combine the figures
combined_fig = Figure(data=[*____.____, *monthly_avg_fig.____])

# Add a title
combined_fig.update_layout(title='Sydney Temperature Analysis')

# Show the combined figure
combined_fig.show()
Code bearbeiten und ausführen