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

Raise exception when user tries to use set_xlim or set_ylim on a geographic projection #1856

Closed
wants to merge 3 commits into from

Conversation

adrn
Copy link
Contributor

@adrn adrn commented Mar 26, 2013

This is a pretty simple, atomic change but may require some documentation if accepted. I've found that when teaching users about projections, many people expect to be able to change the projection limits (rotate the projection) by using set_xlim() and set_ylim(). The functions work on projection axes:

>>> fig,axes = plt.subplots(1,1,subplots_kw=dict(projection="aitoff"))
>>> axes.set_xlim(0,360)

but don't actually do anything. I propose (with this PR) that these functions explicitly throw a NotImplementedError so it is obvious to the user that they are not actually changing anything by using the limit functions:

>>> axes.set_xlim(0,360)
NotImplementedError: set_xlim and set_ylim are not implemented for geographic projections

@dmcdougall
Copy link
Member

I'm happy with this approach. We should be clear when the user does something wrong, and this achieves that. I would rather the error message be a little more self-explanatory. Perhaps something like,

NotImplementedError: It is not possible to change axes limits for geographic projections

Also, maybe it makes more sense to raise a TypeError to really get across that it's the type of projection that doesn't support this behaviour.

@adrn
Copy link
Contributor Author

adrn commented Mar 26, 2013

Sure, that seems reasonable to me! Will make changes and commit.

@WeatherGod
Copy link
Member

I would consider this a bug of sorts. Maybe this is more the realm of
basemap, but not being able to change the limits would be a major turn-off
to me. At the very least, perhaps we should have the message point users
to basemap?

@mdboom
Copy link
Member

mdboom commented Mar 26, 2013

👍

Axes.set_xlim(self, -np.pi, np.pi)
Axes.set_ylim(self, -np.pi / 2.0, np.pi / 2.0)
raise TypeError("It is not possible to change axes limits "
"for geographic projections.")
Copy link
Member

Choose a reason for hiding this comment

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

If you add "Please consider using Basemap or Cartopy." to the exception, I think this is good to go.

@pelson
Copy link
Member

pelson commented May 13, 2013

Merged with e528dad.

Thanks @adrn.

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.

None yet

5 participants