Multi-Line Plots
Sometimes a story has more than one character. You don't just want to see the maximum temperature, and then separately look at the minimum — you want to see them together. That is exactly what multiple line plots are for.
1The “why”: comparing stories on one page
Put a week of Gangtok's maximum and minimum temperatures on the same chart and two insights appear that neither chart alone could give you:
- Comparison — the vertical gap between the lines is the daily temperature range. You can see instantly which day was most extreme.
- Trends — is the week getting warmer or colder? Are the mornings getting chillier while the afternoons stay hot?
Putting related datasets on one chart makes comparisons clear and reveals insights you would miss on separate graphs.
2The “data”: side-by-side storytellers
For multiple lines, your data needs to be organised like this:
- One common X-axis — usually the time component. Both lines share the same
days_of_weektimeline. - Multiple Y-axis datasets — each line gets its own list of values. One for
max_temperatures, one formin_temperatures. Each list tells the story of one trend.
3The “plotting”: one call per line
Drawing multiple lines is surprisingly simple — you just call plt.plot() once for each line. Each call gets its own Y data, and can carry its own style:
color='red'for the maximum, suggesting heat.color='blue'for the minimum, suggesting cold.label="…"— a name tag for the line, which the legend will use later.
4The “legend”: your chart's translator
With more than one line, how does anyone know which is which? That is where the legend steps in. Try switching it off below while both lines are drawn — the chart immediately becomes a guessing game.
Draw each line, then try turning the legend off while both are showing.
import matplotlib.pyplot as plt
days_of_week = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]
max_temperatures = [22, 24, 23, 25, 26, 24, 23]
min_temperatures = [15, 16, 15, 17, 18, 16, 15]
plt.plot(days_of_week, max_temperatures, color="red",
label="Max Temperature (°C)")
plt.plot(days_of_week, min_temperatures, color="blue",
label="Min Temperature (°C)")
plt.title("Weekly Temperature Trends in Gangtok")
plt.xlabel("Day of the Week")
plt.ylabel("Temperature (°C)")
plt.legend(loc="upper left")
plt.show()✅ plt.legend() gathers the label= from every plt.plot() call and draws the key. Now the chart explains itself.
The legend works in two steps, and both are required:
- The magic
label=— in eachplt.plot()call you attach a name tag to that line. - The
plt.legend()call— made once, after all your lines are plotted. It gathers up every label and draws a neat box showing each line's style next to its name.
label= with no plt.legend() call is invisible — matplotlib remembers the name but never draws it. And plt.legend() with no labels produces an empty box. You need both.5Putting it all together
Here is the complete program that recreates the weekly temperature chart. Run it, then try changing a colour, moving the legend, or adding a third line for the average temperature.
6Recap
| Call | What it does | How many times? |
|---|---|---|
| plt.plot(x, y, color=…, label=…) | Draws one line | Once per line |
| plt.title() / xlabel() / ylabel() | Describes the chart | Once |
| plt.legend(loc=…) | Draws the key from the labels | Once, after all plots |
| plt.savefig(…) | Saves the chart to an image file | Once, before show() |
| plt.show() | Displays the finished chart | Once, last |
How do you draw two lines on the same chart?
You set label= on both plots but the chart shows no key. What is missing?
What does loc='upper left' do?