observablehq / observablehq/plot

Interval scale produces wrong ticks and labels

Open
#1,991 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
5.4k
Forks
244
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the x-axis interval-scale handling and tick generation used by the Plot.plot configuration in the example. Reproduce the supplied pre-binned data case, then verify that interval 0.05 produces correctly positioned, non-duplicated ticks and labels both with default ticks and with explicit ticks.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.