Aan de slagGa gratis aan de slag

Coloring student scores bar graph

The school board was well-pleased with your previous plot, but they are wondering if there is a way for you to visually identify good and bad performers.

This would be a great opportunity to utilize color, specifically a color scale. You think a scale from red (worst marks) to green (good marks) would be great.

Part of your previous code to create the student scores bar chart has been provided.

The student_scores DataFrame is also available. You can print it out and inspect it in the console.

Deze oefening maakt deel uit van de cursus

Introduction to Data Visualization with Plotly in Python

Cursus bekijken

Oefeninstructies

  • Create a color scale list from red (255, 0, 0) to green (3, 252, 40).
  • Set the color argument to the appropriate numerical column.
  • Use my_scale as the color scale for the plot.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Create your own continuous color scale
my_scale = ["rgb(____)", "rgb(____)"]

# Create the bar plot
fig = px.bar(data_frame=student_scores, 
             x="student_name", y="score", title="Student Scores by Student",
             # Set the color variable and scale
             color="____",
             color_continuous_scale=____
             )

# Show the plot
fig.show()
Code bewerken en uitvoeren