GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix floating-point artefacts in tick labels (snap near-zero ticks to tick0) by kirthi-b · Pull Request #7901 · plotly/plotly.js

Conversation

@kirthi-b

@kirthi-b kirthi-b commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

What this fixes

Tick labels could show values like -0.0000000000000000888178 where the tick should read 0. Reported in #7765.

Why it happens

calcTicks builds tick values by repeated increments. With an unspecified tick0 (so it defaults to 0), a tick that should sit exactly on 0 can come out as a tiny nonzero value such as -8.9e-17 due to floating-point roundoff. The default numeric formatter rounds that away, but d3-format specs like ~r pass the value straight through and print it in full.

The change

In calcTicks, when a computed tick value is far closer to tick0 than one dtick (within dtick times 1e-6), snap it to exactly tick0. This matches the narrow fix alexcjohnson outlined in the issue: with a default tick0 of 0 it is unambiguous that such a tick belongs at zero. It is limited to linear axes and numeric dtick, so date, log, and category axes are untouched.

Known limitation, same one noted in the issue: this snaps to tick0, so it does not cover the case where someone sets a nonzero tick0 but a tick still falls on zero (for example tick0=1, dtick=0.1). That would need a separate heuristic and is left out to keep this change small.

Test

Added a jasmine test in axes_test.js that builds the reproducing range ([-0.65, 0.65], tick0 0, dtick 0.2) and checks that with tickformat ~r the zero tick renders as "0" rather than the artefact, and that the default format stays correct. Verified it fails without the source change and passes with it.

Thanks to camdecoster for offering to prioritize review of a PR for this.

Fixes #7765

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
kirthi-b and others added 4 commits July 12, 2026 16:37
@kirthi-b
Snap near-zero tick values to tick0 to fix float artefacts in labels
0153c9e
When ticks are built by repeated increments, a tick that should sit
exactly on tick0 can come out as a tiny nonzero value like -8.9e-17.
The default numeric format rounds that away, but d3-format specs such as
`~r` render it literally, so a tick at zero showed as
-0.0000000000000000888178. When a computed tick value is far closer to
tick0 than one dtick, snap it to exactly tick0.

Fixes plotly#7765
@camdecoster
Refactor helper function to generalize snapping
7d556e2
@camdecoster
Add additional test and refactor a bit
0595efd
@camdecoster
Add draftlog
f846c5d
camdecoster
camdecoster approved these changes Jul 13, 2026
View reviewed changes

@camdecoster camdecoster left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! You're actually the third person to submit a PR for this issue, so I guess it's time I actually followed through on the review. Your initial solution to snap to tick0 was a good idea, but I decided to generalize it more to allow for snapping to a multiple of the tick delta (which is what the user that wrote #7810 was doing). I also added another test for a non-snap-to-zero case. Collaboration all around! Once CI passes I'll get this merged.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@camdecoster
camdecoster merged commit a677f28 into plotly:master Jul 13, 2026
84 of 85 checks passed

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Jul 13, 2026
Fix near-zero linear tick labels #7823
Closed
fix: snap tick values to grid before applying custom tickformat #7810
Closed
fix(axes): format tick labels correctly for small numbers in exponential notation #7768
Merged
@RolT RolT mentioned this pull request Aug 25, 2026
Nearly zero axis label - Floating point rounding error #7069
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@camdecoster camdecoster camdecoster approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

[BUG]: floating-point artefacts in tick labels

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@kirthi-b @camdecoster
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.