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

Interval scale produces wrong ticks and labels #1991

Open
spren9er opened this issue Feb 13, 2024 · 0 comments
Open

Interval scale produces wrong ticks and labels #1991

spren9er opened this issue Feb 13, 2024 · 0 comments

Comments

@spren9er
Copy link

According to Observable Plot docs, interval scale can take numbers:

The option can also be specified as a number, in which case it will be promoted to a numeric interval with the given step.

In the following example, I apply an interval transform and an interval scale (both given by a number) to pre-binned data. Resulting plot has wrong x-axis ticks and labels.

Example

See also Observable Notebook.

Given data (already binned with bin width 0.05 or bin step -20)

data = [
  { "x": 0.15, "y": 1 },
  { "x": 0.25, "y": 5 },
  { "x": 0.35, "y": 85 },
  { "x": 0.4,  "y": 196 },
  { "x": 0.45, "y": 268 },
  { "x": 0.5,  "y": 380 },
  { "x": 0.55, "y": 354 },
  { "x": 0.6,  "y": 658 },
  { "x": 0.65, "y": 7382 },
  { "x": 0.7,  "y": 45588 },
  { "x": 0.75, "y": 67028 },
  { "x": 0.8,  "y": 52965 },
  { "x": 0.9,  "y": 95069 },
  { "x": 0.95, "y": 30982 }
]

With Interval transform, but without Interval scale

Plot.plot({
  marks: [
    Plot.rectY(data, { x: "x", y: "y", interval: 0.05 })
  ]
})

interval_scale_off

This looks good. Now, I want to add an interval scale:

With Interval transform, with Interval scale

Plot.plot({
  x: {
    interval: 0.05
  },
  marks: [
    Plot.rectY(data, { x: "x", y: "y", interval: 0.05 })
  ]
})

interval_scale_on

This plot has a wrong x-axis:

  • Ticks are off by 0.05
  • 0.3 and 0.8 are each shown twice
  • 0.2 and 0.4 are missing

Increasing the number of ticks produces a correct plot:

With Interval transform, with Interval scale, and with explicit ticks

Plot.plot({
  x: {
    interval: 0.05,
    ticks: 18
  },
  marks: [
    Plot.rectY(data, { x: "x", y: "y", interval: 0.05 })
  ]
})

interval_scale_on_ticks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant