Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: better error message for shared axes and axis('equal') #21318

Merged
merged 3 commits into from Nov 23, 2021

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Oct 8, 2021

PR Summary

Closes #11416

The error message was pretty mysterious if you called ax.axis('equal') on a shared axes...

Not clear that the functionality users are trying to get from this could not be provided, but at least clarifying the error message will help...

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@tacaswell
Copy link
Member

This PR is affected by a re-writing of our history to remove a large number of accidentally committed files see discourse for details.

To recover this PR it will need be rebased onto the new default branch (main). There are several ways to accomplish this, but we recommend (assuming that you call the matplotlib/matplotlib remote "upstream"

git remote update
git checkout main
git merge --ff-only upstream/main
git checkout YOUR_BRANCH
git rebase --onto=main upstream/old_master
# git rebase -i main # if you prefer
git push --force-with-lease   # assuming you are tracking your branch

If you do not feel comfortable doing this or need any help please reach out to any of the Matplotlib developers. We can either help you with the process or do it for you.

Thank you for your contributions to Matplotlib and sorry for the inconvenience.

@jklymak jklymak force-pushed the fix-improve-shared-aspect-error branch from 5d37e45 to 400445a Compare October 20, 2021 20:34
@jklymak jklymak force-pushed the fix-improve-shared-aspect-error branch from 400445a to 2ad34af Compare October 20, 2021 20:39
@jklymak
Copy link
Member Author

jklymak commented Oct 20, 2021

-- rebased

Comment on lines 2052 to 2053
raise RuntimeError("'equal' is not allowed on shared "
"axes, try 'scaled' instead.")
Copy link
Member

Choose a reason for hiding this comment

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

Is the original exception important here, or should we do from None here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it a RunTimeError that we want to re-raise here, or should we change it to ValueError instead since you are saying that value isn't allowed?

Copy link
Member Author

Choose a reason for hiding this comment

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

As above, I'm not sure I can even trigger this so lets try removing...

@tacaswell tacaswell added this to the v3.6.0 milestone Oct 20, 2021
self.set_aspect('equal', adjustable='datalim')
try:
self.set_aspect('equal', adjustable='datalim')
except RuntimeError:
Copy link
Member

Choose a reason for hiding this comment

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

We only want to catch the above exception, right? Technically, we should make sure not to catch other RuntimeErrors here, either by inspecting the message or by using a custom exception above.

But I'm not sure if we have to be that pedantic. Catching the wrong exception does not change control flow, it could only issue a non-instructive error message.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, looking back at it now, I'm not sure what this is supposed to catch. set_aspect does not call apply_aspect, and apply_aspect is only called at draw time so far as I can tell. I couldn't figure out a test for this, so lets see if anything fails just removing it again.

Copy link
Member Author

Choose a reason for hiding this comment

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

Confirmed, this doesn't fail any tests - so I'm not even sure this was reachable. Sorry I don't remember what prompted this int he first place!

@timhoffm timhoffm merged commit 73304d2 into matplotlib:main Nov 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RuntimeError: adjustable='datalim' is not allowed when both axes are shared.
5 participants