Skip to content

Flat line plot gets wrong y-axis tick mark #2348

Closed
d3/d3-format
#147

Description

@to-mi

Drawing a plot with flat y values gives wrong tick mark for y axis.

Example:

Plot.plot({
  marks: [
    Plot.line([
      {x: 0.0, y: 0.5},
      {x: 1.0, y: 0.5},
      {x: 2.0, y: 0.5},
      {x: 3.0, y: 0.5},
      {x: 4.0, y: 0.5},
      {x: 5.0, y: 0.5},
      {x: 6.0, y: 0.5},
      {x: 7.0, y: 0.5},
      {x: 8.0, y: 0.5},
      {x: 9.0, y: 0.5}
    ], {x: "x", y: "y", tip: "xy"})
  ]
})

Result has tick mark 1 at the level of the line. The tip shows correctly 0.5. (Same example with y-values at 1.5 seems to give 2 as tick mark.)

Image

(Tried to browse through the issues to see if this has been reported already but didn't find matching ossie.)

Activity

  1. added
    bug
    on Oct 15, 2025
  2. mbostock commented on Jan 13, 2026

    @mbostock
    Member

    Here’s an even smaller reduction…

    Image
    Plot.dot([[0.5, 0.5]]).plot()

    You can workaround it by setting the tickFormat option explicitly, say:

    Image
    Plot.dot([[0.5, 0.5]]).plot({x: {tickFormat: ""}, y: {tickFormat: ""}})

    The bug is in the determination of the tick format precision when the scale’s domain is collapsed (here, [0.5, 0.5], meaning that the start and end values are the same). When the domain is collapsed we should not attempt to compute the precision but should instead use the default of 6 while trimming trailing zeroes.

  3. mbostock commented on Jan 13, 2026

    @mbostock
    Member

    This is really a bug in d3-scale/d3-format:

    d3.scaleLinear([0.5, 0.5], [0, 100]).tickFormat(10)(0.5) // "1"

    The problem is that tickStep returns zero for a collapsed domain:

    d3.tickStep(0.5, 0.5, 10) // 0

    Then precisionFixed returns 0 (which should probably be NaN or Infinity?):

    d3.precisionFixed(0) // 0

    This then results in a zero precision format:

    d3.format(",.0f")(0.5) // "1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions