Keeping Scales to Whole Numbers in Plot

Hi all,

I’m trying to keep my scale to whole numbers since the data I’m displaying will never be a float.

My domain on this example is [0, 3], but the max is dynamic and could be as high as 20, so I don’t want to explicitly set it to every possible integer. For example, if it’s 10, it looks like this which is great:

Any ideas?

Edit: Sorry, I should have said that this is in Plot.

You’re not alone :slight_smile: Here’s the relevant issue Interval-aware default tick formats · Issue #932 · observablehq/plot · GitHub.

What you could do in the meantime is filter out the non-int ticks with:

tickFormat: d => d > Math.floor(d) ? "" : `${d}`
2 Likes