Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

heatmap mark? #1122

Closed
Fil opened this issue Nov 29, 2022 · 4 comments
Closed

heatmap mark? #1122

Fil opened this issue Nov 29, 2022 · 4 comments
Assignees
Labels
enhancement New feature or request geo Maps and projections

Comments

@Fil
Copy link
Contributor

Fil commented Nov 29, 2022

I sometimes see users trying to make heatmaps with Plot.cell, which results in incorrect charts when x and y are continuous. The recommended approach (until now) was to use Plot.bin to create the small squares (or rather, rectangles), as x/y bins. However with projections, this is now incomplete, and we should have a solution for heatmaps in the projected space. Like hexbin, but based on squares (or any other tessellation?). There's probably a lot of code to share with hexbin, the most difficult part to decide might be the API?

@Fil Fil self-assigned this Nov 29, 2022
@mbostock mbostock added the enhancement New feature or request label Dec 1, 2022
@Fil Fil added the geo Maps and projections label Dec 1, 2022
@mbostock
Copy link
Member

mbostock commented Dec 14, 2022

Related or duplicate of #984?

Also not sure I follow why the recommended approach of rect + bin is “incomplete” with re. to projections, since we support projecting rects now (at least for cylindrical projections under the normal aspect).

I used rect for this recently for Advent of Code:

untitled (77)

Plot.plot({
    grid: true,
    round: true,
    x: {domain: [grid.x1 - 0.5, grid.x2 + 0.5]},
    y: {domain: [grid.y2 + 0.5, -0.5]},
    color: {
      domain: ["rock", "sand", "source"],
      range: ["#5a4d41", "#c2b280", "red"]
    },
    marks: [
      Plot.rect(grid.values, {
        x1: (d, i) => grid.x1 + i % grid.m - 0.5,
        y1: (d, i) => grid.y1 + Math.floor(i / grid.m) - 0.5,
        x2: (d, i) => grid.x1 + i % grid.m + 0.5,
        y2: (d, i) => grid.y1 + Math.floor(i / grid.m) + 0.5,
        fill: (d) => d
      })
    ]
  })

I originally used the interval option (1) but for the smaller grids I wanted the rects to be centered on their value rather than between values.

@mbostock mbostock mentioned this issue Dec 14, 2022
@mbostock
Copy link
Member

I would like to better understand how continuous heatmaps are commonly expressed. Do we want a sparse sample-based approach as with the pixel mark in #1185 (which is really just an optimization of the existing rect mark + interval transform)? Or does the user want to supply a continuous function of xy that is them sampled automatically (in a grid) by Plot? Or maybe the user supplies dense samples in a grid (similar to ImageData) so that the x and y channels can be implicit? Or all of the above?

@Fil
Copy link
Contributor Author

Fil commented Dec 18, 2022

@mbostock
Copy link
Member

Fixed in #1196.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request geo Maps and projections
Projects
None yet
Development

No branches or pull requests

2 participants