Labels and Titles
Part of the Data and Plots section of Coddy's Machine Learning journey. Lesson 20 of 60.
By the end of this chapter, you will draw charts like this one:
It starts with words. A bare line could be money, minutes or meters. A title and two axis labels say which:
months = [1, 2, 3, 4, 5, 6]
savings = [120, 250, 310, 480, 520, 700]
plt.plot(months, savings)
plt.title("My Savings")
plt.xlabel("Month")
plt.ylabel("Savings ($)")
plt.show()Each takes one string, so an f-string works too. Put the unit in the label, and call all three before plt.show(), which finishes the chart.
Challenge
MediumA solar panel logged its power every morning hour. The starter reads the panel's name and plots its line. Finish the chart:
- Title it with the name, a space and
Output: the nameShedgivesShed Output. - Label the axis across
Hourand the axis upPower (W). - Show the chart.
Yours should look like this one, for a panel named Balcony:
Your program prints nothing. Coddy describes your chart in the output.
Try it yourself
import matplotlib.pyplot as plt
panel = input()
hours = [6, 7, 8, 9, 10, 11, 12]
watts = [40, 95, 160, 210, 255, 280, 290]
# Don't change the line below
plt.plot(hours, watts)
# Write your code below
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Data and Plots
2NumPy Arrays
Creating ArraysShape and SizeRanges of NumbersIndexing and SlicingRecap: Temperature Grid5Line and Scatter Plots
Labels and TitlesScatter PlotsSeveral Lines and LegendsColors and MarkersFigures and AxesRecap: Weekly StepsPractice on your own: Online Python compiler