Menu
CoddyTech

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:

A line chart of 5 hourly temperatures that climbs from 12 to 22 degrees at hour 4, then dips to 20

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 icon

Challenge

Easy

A sunflower was measured every week. heights holds weeks 1 to 6, in centimeters.

  1. Import matplotlib.pyplot as plt.
  2. Make a list weeks: 1 to 6.
  3. Plot the heights against the weeks and show the chart.

Yours should look like this one, a tomato plant's:

A line chart climbing from 3 cm in week 1 to 16 cm in week 6

Coddy checks your chart and describes it in the output.

Try it yourself

heights = [2, 5, 9, 14, 18, 21]

# Write your code below
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Data and Plots

Practice on your own: Online Python compiler