Skip to content

Deprecate getting/setting pix on WCSAxes Spine - #13989

Merged
larrybradley merged 4 commits into
astropy:mainfrom
dstansby:wcs-pix
Mar 31, 2023
Merged

larrybradley merged 4 commits into
astropy:mainfrom
dstansby:wcs-pix

Conversation

@dstansby

@dstansby dstansby commented Nov 6, 2022 •

Copy link
Copy Markdown
Contributor

Description

(this is a revival of #12621)

When using Matplotlib, it is generally only safe to calculate pixel coordinates of artists at draw time, as that is when the figure DPI is set in stone. Calculating the pixel coordinates before drawing can lead to issues like #12568.

This PR fixes this issue for WCSAxes Spines by ensuring that pixel calculations are done at draw time. It also deprecates getting and setting pixel coordinates.

This pull request is to partly address #12568. Before that issue can be fully resolved I think there is also a fix required on the Matplotlib side.

With the sample code given in #12568, this improves the resulting plot from this (on current main):
grid-False

to this:
grid-False-new

Checklist for package maintainer(s)

This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.

  • 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 "When to rebase and squash commits".
  • 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.
  • 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 a milestone set? Milestone must be set but astropy-bot check might be missing; do not let the green checkmark fool you.
  • 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.

@dstansby

Copy link
Copy Markdown
Contributor Author

Test failures look real.

@pllim

pllim commented Dec 2, 2022

Copy link
Copy Markdown
Member

Hello!

Test failures look real.

Does this mean that we cannot deprecate? Or does it mean that the tests or some code need update?

Do you need assistance?

@dstansby

dstansby commented Dec 2, 2022

Copy link
Copy Markdown
Contributor Author

Needs an update, I should be able to look into this myself when I have time.

@dstansby
dstansby marked this pull request as ready for review December 8, 2022 23:01
@dstansby

dstansby commented Dec 8, 2022

Copy link
Copy Markdown
Contributor Author

👍 this should be good for review now, sorry for the delay!

Comment thread astropy/visualization/wcsaxes/frame.py Outdated
self._world = None
else:
self._pixel = self.parent_axes.transData.transform(self._data)
self._data = value

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this line can be removed. It's not a duplicate of line 149.

Comment thread astropy/visualization/wcsaxes/frame.py Outdated
self._data = value
if value is None:
self._pixel = None
self._data = None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here.

@dstansby

Copy link
Copy Markdown
Contributor Author

👍 done

@pllim

pllim commented Mar 15, 2023

Copy link
Copy Markdown
Member

@larrybradley , please re-review. Thanks!

@astrofrog astrofrog left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me! But could we include an image test for the bugfix, even if it needs updating once the remaining issues are resolved in follow-up PRs/matplotlib?

@astrofrog astrofrog left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks good to me!

I went down a rabbit hole trying to set up a test for this because it does not happen with PNG output, but does with e.g. PDF. So I have been working on extending pytest-mpl to be able to compare PDF output (see matplotlib/pytest-mpl#194). So let's plan to add a regression test in future once the pytest-mpl changes are in a release.

@astrofrog astrofrog added the zzz 💤 merge-when-ci-passes Do not use: We have auto-merge option now. label Mar 31, 2023
@astrofrog

Copy link
Copy Markdown
Member

(I have rebased this to make sure the test failures were unrelated)

@pllim

pllim commented Mar 31, 2023

Copy link
Copy Markdown
Member

@larrybradley , do you want to re-review since you requested changes?

@larrybradley larrybradley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. I just pushed a small change to remove an unnecessary line.

@pllim pllim added the API change PRs and issues that change an existing API, possibly requiring a deprecation period label Mar 31, 2023
@larrybradley
larrybradley merged commit b075043 into astropy:main Mar 31, 2023
@pllim

pllim commented Mar 31, 2023

Copy link
Copy Markdown
Member

Thanks, all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API change PRs and issues that change an existing API, possibly requiring a deprecation period Refactoring visualization.wcsaxes visualization zzz 💤 merge-when-ci-passes Do not use: We have auto-merge option now.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants