Get startedGet started for free

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.

This exercise is part of the course

Introduction to Data Visualization with Plotly in Python

View Course

Exercise instructions

  • 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.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# 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()
Edit and Run Code