Get startedGet started for free

Encoding time by color

The screen only has two dimensions, but we can encode another dimension in the scatter plot using color. Here, we will visualize the climate_change dataset, plotting a scatter plot of the "co2" column, on the x-axis, against the "relative_temp" column, on the y-axis. We will encode time using the color dimension, with earlier times appearing as darker shades of blue and later times appearing as brighter shades of yellow.

This exercise is part of the course

Introduction to Data Visualization with Matplotlib

View Course

Exercise instructions

  • Using the ax.scatter method add a scatter plot of the "co2" column (x-axis) against the "relative_temp" column.
  • Use the c key-word argument to pass in the index of the DataFrame as input to color each point according to its date.
  • Set the x-axis label to "CO2 (ppm)" and the y-axis label to "Relative temperature (C)".

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

fig, ax = plt.subplots()

# Add data: "co2", "relative_temp" as x-y, index as color
____

# Set the x-axis label to "CO2 (ppm)"
____

# Set the y-axis label to "Relative temperature (C)"
____

plt.show()
Edit and Run Code