When should you use a colorbar instead of a discrete legend, and what does that tell you about the underlying variable?

Quick Overview

Asks when a chart should show a colorbar and when it should show a discrete legend for a color-encoded variable. It tests whether you can tell continuous, ordinal and categorical data apart and pick an encoding that does not mislead readers about order.

When should you use a colorbar instead of a discrete legend, and what does that tell you about the underlying variable?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

When should you use a colorbar instead of a discrete legend, and what does that tell you about the underlying variable? Assume you are plotting with Matplotlib or Seaborn and color encodes one extra variable, as in a scatter plot colored by a third column or a heatmap. ```hint Look at the values between colors Ask whether a value halfway between two colors means anything for this variable, and whether its values have an order. ``` ### What a Strong Answer Covers - Which kinds of variables call for a colorbar and which call for a discrete legend - What each choice tells the reader about order and about values between the colors shown - How to show binned or ordinal data, for example with a stepped colorbar - What goes wrong when the wrong one is used, with a concrete example - How to produce each one in Matplotlib or Seaborn ### Follow-up Questions - How do you choose between a sequential and a diverging colormap for a colorbar? - Cluster labels stored as integers 0 to 4 get a continuous colormap by default in `plt.scatter`. How do you fix that, and why does it matter? - What would you do when a categorical variable has 25 levels and the legend becomes unreadable? - Why is a rainbow colormap such as `jet` a poor choice for continuous data?

Overview: Asks when a chart should show a colorbar and when it should show a discrete legend for a color-encoded variable. It tests whether you can tell continuous, ordinal and categorical data apart and pick an encoding that does not mislead readers about order.

General logo
General
Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

When should you use a colorbar instead of a discrete legend, and what does that tell you about the underlying variable?

Assume you are plotting with Matplotlib or Seaborn and color encodes one extra variable, as in a scatter plot colored by a third column or a heatmap.

What a Strong Answer Covers Guidance

  • Which kinds of variables call for a colorbar and which call for a discrete legend
  • What each choice tells the reader about order and about values between the colors shown
  • How to show binned or ordinal data, for example with a stepped colorbar
  • What goes wrong when the wrong one is used, with a concrete example
  • How to produce each one in Matplotlib or Seaborn

Follow-up Questions Guidance

  • How do you choose between a sequential and a diverging colormap for a colorbar?
  • Cluster labels stored as integers 0 to 4 get a continuous colormap by default in plt.scatter . How do you fix that, and why does it matter?
  • What would you do when a categorical variable has 25 levels and the legend becomes unreadable?
  • Why is a rainbow colormap such as jet a poor choice for continuous data?