Skip to content

fix(scale_widget): keep scale geometry when replacing the scale draw - #114

Merged
PierreRaybaut merged 1 commit into
masterfrom
fix/113-scale-draw-geometry
Oct 29, 2026
Merged

PierreRaybaut merged 1 commit into
masterfrom
fix/113-scale-draw-geometry

Conversation

@PierreRaybaut

Copy link
Copy Markdown
Collaborator

Summary

After replacing the scale draw of an axis (QwtPlot.setAxisScaleDraw), the axis ticks could be misaligned with the grid lines and plot items, until the next scale division change (pan, zoom): a replot did not fix it. This was observed in DataLab, which replaces the bottom scale draw when refreshing its signal view.

Root cause

QwtScaleWidget.setScaleDraw passed the alignment, the scale division and the transformation of the previous scale draw to the new one, but not its position and length. layoutScale() then computed the border distance hint from a zero-length scale (half the width of the end labels instead of 0) and laid the axis out with it, while the stored border distances, used by QwtPlot.canvasMap() for grid lines and plot items, were left unchanged. On the next replot, QwtPlot.updateAxes() set the same border distances again, which did nothing.

Changes

  • QwtScaleWidget.setScaleDraw: also pass the position and the length of the previous scale draw to the new one before laying it out.
  • qwt/tests/test_issue113_scaledraw_geometry.py: regression tests on the horizontal and vertical axes (geometry kept after replacement; axis ends equal to the canvas map ends after a replot).
  • CHANGELOG.md: entry in the unreleased bug fixes.

Tests

  • The new tests fail on master for the horizontal axis (e.g. axis ends 42/483 vs canvas map ends -1/516) and pass with the fix; the vertical axis case passes before and after (regression guard).
  • Full suite (PyQt5, Python 3.11, offscreen): 36 passed, 1 skipped; new tests also pass on Python 3.14 and with the native Windows platform.
  • Ruff format and check: clean.
  • PlotPy test suite (develop) with this branch: 399 passed, 16 skipped.
  • DataLab: loading step.npy gives an X axis aligned with the grid, without any DataLab change.

Fixes #113

After replacing the scale draw of an axis (QwtPlot.setAxisScaleDraw), the
axis ticks could be misaligned with the grid lines and plot items until
the next scale division change: a replot did not fix it.

QwtScaleWidget.setScaleDraw passed the alignment, the scale division and
the transformation of the previous scale draw to the new one, but not its
position and length. layoutScale() then computed the border distance hint
from a zero-length scale (half the width of the end labels instead of 0)
and laid the axis out with it, while the stored border distances used by
QwtPlot.canvasMap() were left unchanged. On the next replot,
updateAxes() set the same border distances again, which did nothing.

- setScaleDraw: also pass the position and the length of the previous
  scale draw to the new one before laying it out.
- Regression tests on the horizontal (reproducing the issue) and vertical
  axes: geometry kept, axis ends equal to the canvas map ends.
- Changelog entry.

Fixes #113

Assisted-by: Claude Opus 5.5
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

Successfully merging this pull request may close these issues.

Axis ticks misaligned with canvas grid after replacing the scale draw

1 participant