0
0
Matplotlibdata~30 mins

Time series with fill_between in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Time Series Visualization with fill_between
📖 Scenario: You work as a data analyst for a weather station. You have daily temperature data for a week. You want to visualize the temperature changes and highlight the area between the minimum and maximum temperatures each day.
🎯 Goal: Create a time series plot of daily temperatures using matplotlib. Use fill_between to shade the area between the minimum and maximum temperatures for each day.
📋 What You'll Learn
Create lists for dates, minimum temperatures, and maximum temperatures.
Create a variable for the color to fill between the min and max temperatures.
Use plt.fill_between to shade the area between min and max temperatures.
Plot the min and max temperature lines on the same graph.
Display the plot with labels and a title.
💡 Why This Matters
🌍 Real World
Visualizing temperature ranges helps meteorologists and planners understand daily weather variations and prepare accordingly.
💼 Career
Data analysts and scientists often use time series plots with shaded areas to show ranges, confidence intervals, or variability in data.
Progress0 / 4 steps
1
Create the temperature data lists
Create three lists called dates, min_temps, and max_temps with these exact values:
dates = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
min_temps = [12, 14, 13, 15, 14, 16, 15]
max_temps = [20, 22, 21, 23, 22, 24, 23]
Matplotlib
Need a hint?

Use square brackets [] to create lists with the exact values given.

2
Set the fill color for the shaded area
Create a variable called fill_color and set it to the string 'lightblue' to use as the color for the area between min and max temperatures.
Matplotlib
Need a hint?

Assign the string 'lightblue' to the variable fill_color.

3
Plot the temperature lines and fill the area between
Import matplotlib.pyplot as plt. Use plt.fill_between with dates, min_temps, and max_temps and the color set to fill_color. Then plot the min_temps and max_temps lines using plt.plot with dates as x-axis. Add labels for x-axis as 'Day' and y-axis as 'Temperature (°C)'. Add the title 'Daily Min and Max Temperatures'.
Matplotlib
Need a hint?

Remember to import matplotlib.pyplot as plt. Use plt.fill_between to shade between min and max temperatures. Then plot lines for min and max temperatures. Add labels and title for clarity.

4
Display the plot
Add a line to display the plot using plt.show().
Matplotlib
Need a hint?

Use plt.show() to display the plot window.