Skip to content

Can't display more than 2 swatches for quantitative data #827

Answered by mbostock
stevage asked this question in Q&A
Discussion options

You must be logged in to vote

The swatches legend type is only supported for discrete quantitative color scales, but you’re using a continuous quantitative color scale here. (We should probably throw an error in this case.) Per the README:

For quantitative color scales, it defaults to ramp but may be set to swatches for a discrete scale (most commonly for threshold color scales); for ordinal color scales and symbol scales, only the swatches value is supported.

The swatches legend type will display all the values in the scale’s domain, which in the case of a continuous scale is the lower and upper bound, which appears to be [0, 15] in your case.

The default legend for a linear color scale is:

Plot.legend({
  color: {

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@stevage
Comment options

@stevage
Comment options

@stevage
Comment options

@stevage
Comment options

@mbostock
Comment options

Answer selected by stevage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #826 on March 24, 2022 22:38.