Get startedGet started for free

Building a scatterplot with specific colors

In your work as a data analyst, you have been engaged by a group of Antarctic research scientists to help them explore and report on their work.

They have spent a lot of time collating data on penguin species, but are having difficulty visualizing it to understand what is happening. Specifically, they have asked if you can help them plot their data in relation to statistics on the penguins' body attributes. They also suspect there is some pattern related to species, but are unsure how to plot this extra element.

In this exercise, you will help the scientific team by creating a scatterplot of the 'Culmen' (upper beak) attributes of the scientists' penguin data, ensuring that the species are included as specific colors.

You have been provided a penguins DataFrame.

This exercise is part of the course

Introduction to Data Visualization with Plotly in Python

View Course

Exercise instructions

  • Create a color_map dictionary that maps the species (Adelie, Gentoo, Chinstrap) to the RGB codes (235, 52, 52), (235, 149, 52), and (67, 52, 235) respectively.
  • Create a basic scatterplot using plotly.express for the penguins data, visualizing the features Culmen Length (mm) on the x-axis and Culmen Depth (mm) on the y-axis.
  • Set the colors of the scatterplot to be the Species and use the color_map that you created.

Hands-on interactive exercise

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

# Set up the color map
color_map = {'Adelie': '____' , 'Gentoo': '____', 'Chinstrap': '____'}

# Create a scatterplot
fig = px.scatter(data_frame=____, title="Penguin Culmen Statistics",
    x=____,
    y=____,
    # Set the colors to use your color map
    color=____,
    color_discrete_map=____
)

# Show your work
fig.show()
Edit and Run Code