IniziaInizia gratis

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.

Questo esercizio fa parte del corso

Introduction to Data Visualization with Matplotlib

Visualizza il corso

Istruzioni dell'esercizio

  • 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)".

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

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()
Modifica ed esegui il codice