Skip to content

Raster perserveAspectRatio? #2286

Answered by mbostock
aboveyunhai asked this question in Q&A
Feb 22, 2025 · 3 comments · 4 replies
Discussion options

You must be logged in to vote

Removing (or altering) the preserveAspectRatio attribute will mean that the raster data will not align with the position scales (Plot’s coordinate system). So, I don’t think you want to do that; or if you do, you want to suppress the x-axis so that it’s not misleading.

Instead, I recommend you use Plot’s aspectRatio option, and set it to 1 if you want the data to be displayed in a square aspect ratio (as with equirectangular coordinates). This option will then compute an appropriate default height for the plot.

Plot.plot({
  color: {
    scheme: "BuGn",
    legend: true
  },
  aspectRatio: 1,
  marks: [
    Plot.raster(data, {
      width: 135,
      height: 231,
      x1: 93.835,
      x2

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@aboveyunhai
Comment options

Comment options

You must be logged in to vote
3 replies
@aboveyunhai
Comment options

@mbostock
Comment options

@aboveyunhai
Comment options

Answer selected by aboveyunhai
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants