Skip to content

Raster mark does not show all data? #2318

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

You must be logged in to vote

You need to do a couple things differently:

  • You need to offset the raster sample positions by 0.5 so that they are sampled from the middle of the pixel (grid cell) rather than the corner
  • You need to set the domains of the x and y scales (because the domains are otherwise inferred from the sample positions, but you want to expand the domains so that they cover the full pixel)

Here is a fixed version adapted from the documentation:

Plot.plot({
  color: { legend: true },
  x: { domain: [0, w] },
  y: { domain: [0, h] },
  marks: [
    Plot.raster(
      { length: w * h },
      {
        width: w,
        height: h,
        x: (_, i) => (i % w) + 0.5,
        y: (_, i) => Math.floor(i / w) +

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@mbostock
Comment options

@yurivish
Comment options

Answer selected by yurivish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
bug Something isn’t working
2 participants
Converted from issue

This discussion was converted from issue #2317 on April 23, 2025 19:15.