Your First Plot
Part of the Data and Plots section of Coddy's Machine Learning journey. Lesson 4 of 60.
A list of numbers hides its story. A chart tells it at a glance:
Four lines of code drew it:
import matplotlib.pyplot as plt
hours = [1, 2, 3, 4, 5]
temps = [12, 15, 19, 22, 20]
plt.plot(hours, temps)
plt.show()plt.plot(x, y) pairs each x with its y and joins the dots. plt.show() sends the chart to the Plots tab.
Challenge
EasyA sunflower was measured every week. heights holds weeks 1 to 6, in centimeters.
- Import
matplotlib.pyplotasplt. - Make a list
weeks: 1 to 6. - Plot the heights against the weeks and show the chart.
Yours should look like this one, a tomato plant's:
Coddy checks your chart and describes it in the output.
Try it yourself
heights = [2, 5, 9, 14, 18, 21]
# 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 GridPractice on your own: Online Python compiler