Skip to content

Improved placement of WCSAxes tick labels for non-perpendicular grids or ticks#19057

Open
ayshih wants to merge 5 commits into
astropy:mainfrom
ayshih:ticklabel_fixes
Open

Improved placement of WCSAxes tick labels for non-perpendicular grids or ticks#19057
ayshih wants to merge 5 commits into
astropy:mainfrom
ayshih:ticklabel_fixes

Conversation

@ayshih
Copy link
Copy Markdown
Contributor

@ayshih ayshih commented Dec 15, 2025

Description

This pull request improves the placement of WCSAxes tick labels, particularly for non-perpendicular grids or ticks. Specifically (in order of commits):

  • There were two approaches to calculating tick-label positions: a legacy approach for rectangular plot frames and a general approach for arbitrary spines. There's an 11-year-old comment that the legacy approach should be removed, but it continues to be the code path whenever the plot frame is rectangular, even for overlay grids where the gridlines are not rectangular. This PR removes that code path.
  • The general approach for calculating tick-label positions had a bug for a sector of label directions (was only evident for non-rectangular frames due to the previous bullet).
  • The general approach for calculating tick-label positions did not uniformly vary with label direction, but functionally "snapped" away from the 45-degree direction, which could result in discontinuities in label positions. This PR fixes this behavior, which also supersedes the fix for the previous bullet.
  • Tick-label positions were padded in the normal direction from the relevant spine, but did not take into account the tick direction, which can be different from the spine normal. This PR additionally pads in the direction parallel to the spine so that the tick label is more visually aligned with where the tick is pointing.

Example script

import matplotlib.pyplot as plt

import astropy.units as u
from astropy.wcs import WCS

sfl = WCS({
    'ctype1': 'RA---SFL',
    'ctype2': 'DEC--SFL',
    'crpix1': 1,
    'crpix2': 1,
})

fig = plt.figure()
ax = fig.add_subplot(projection=sfl)

ax.set_xlim(-90, 90)
ax.set_ylim(-90, 90)

overlay = ax.get_coords_overlay('icrs')

overlay[0].add_tickable_gridline('m', -60*u.deg)
overlay[0].add_tickable_gridline('n', 60*u.deg)

overlay[0].set_ticks(spacing=30*u.deg)

overlay[1].set_ticks(color='red')
overlay[1].set_ticks_position('mn')
overlay[1].set_ticklabel(color='red')
overlay[1].set_ticklabel_position('mn')
overlay[1].set_axislabel("")

overlay.grid()

plt.show()

Before this PR

before

After this PR

Figure_1
  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@github-actions
Copy link
Copy Markdown
Contributor

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@pllim pllim added this to the v7.2.1 milestone Dec 15, 2025
@pllim pllim added Bug backport-v7.2.x on-merge: backport to v7.2.x labels Dec 15, 2025
@ayshih ayshih force-pushed the ticklabel_fixes branch 3 times, most recently from 84cff92 to cc16353 Compare December 16, 2025 15:57
@ayshih ayshih changed the title Fixed placement of WCSAxes tick labels for non-perpendicular grids or ticks Improved placement of WCSAxes tick labels for non-perpendicular grids or ticks Dec 16, 2025
@ayshih
Copy link
Copy Markdown
Contributor Author

ayshih commented Dec 16, 2025

Here is an example of one existing figure test (1) before this PR, (2) after the first three commits, and (3) after the four commits

Example

Before this PR
baseline (1)

After the first three commits (note the better placement of the magenta 0/30/60 deg labels near the middle)
result (2)

After the four commits (note the better horizontal placement of the top labels in the direction parallel to the spine, although in this case it does cause two tick labels to overlap)
result (5)

@github-actions github-actions Bot added the Close? Tell stale bot that this issue/PR is stale label May 16, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Hi humans 👋 - this pull request hasn't had any new commits for approximately 5 months. I plan to close this in a month if the pull request doesn't have any new commits by then.

In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary.

If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock.

If you believe I commented on this pull request incorrectly, please report this here.

@ayshih ayshih force-pushed the ticklabel_fixes branch 4 times, most recently from ef75e7a to 0f79be2 Compare May 29, 2026 13:36
@ayshih ayshih force-pushed the ticklabel_fixes branch 3 times, most recently from 7b7aab7 to 0d635fd Compare May 29, 2026 14:27
@ayshih ayshih force-pushed the ticklabel_fixes branch from 0d635fd to 1675a12 Compare May 29, 2026 14:29
@ayshih
Copy link
Copy Markdown
Contributor Author

ayshih commented May 29, 2026

This PR is ready for review!

I've settled on a sensible approach for taking the tick direction into account when placing the tick label. In short, the tick label is padded out in the tick direction unless the tick is to close to parallel to the spine, and then the tick direction is treated as no more than 60 degrees away from the spine normal. Here's another example of an existing figure test:

Before this PR

baseline (3)

After this PR

result (6)

@ayshih ayshih marked this pull request as ready for review May 29, 2026 14:30
@pllim pllim added backport-v8.0.x on-merge: backport to v8.0.x and removed Close? Tell stale bot that this issue/PR is stale labels May 29, 2026
@Cadair Cadair self-requested a review May 29, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-v7.2.x on-merge: backport to v7.2.x backport-v8.0.x on-merge: backport to v8.0.x Bug visualization.wcsaxes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants