-
-
Notifications
You must be signed in to change notification settings - Fork 7.8k
ENH: Add API to manage view state in custom Axes. #4795
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
Conversation
default implementation saves the view limits. You *must* implement | ||
:meth:`restore_view` if you implement this method. | ||
""" | ||
raise NotImplementedError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be simpler to put the existing code for ordinary axes here instead of leaving these as NotImplementedError, wouldn't it? I don't see any disadvantage, but I'm probably missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably; I'm more curious about the API at the moment.
attn: @OceanWolf, @fariza |
I proposed something similar #2511 but it was rejected. |
That was a slightly different proposal, though. I am not suggesting that the |
I see... In that case why not call it |
|
I like save/restore better than freeze/unfreeze; it's a better description of what is happening. |
What about |
Regarding the names
If the methods are going to be inside the |
@fariza ahh yes, my mistake. we do use a stack, but the stack lies in the tool. So I agree that it looks the best out of the options presented, however I feel it a bit overkill if we generalise this... say in the future we had a state of 100 variables, then we store 100 changes even if we only changed one of them. Maybe if the tool just stored a dictionary of the changes? |
@OceanWolf The variables are stored inside the |
c6151a3
to
34d0143
Compare
Now updated with |
|
||
lastx, lasty, x, y = bbox | ||
|
||
x0, y0, x1, y1 = original_view |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really sure why it's necessary to use the frozen view here. Unlike pan/zoom mode, with zoom-to-rect, there's only one time that the view can change (when the button's released), so I wonder if I can just use the existing view limits here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tacaswell before merging this, can you confirm that this doesn't have any bad side effects?
I have tested it, and it works fine, but I'm not sure that frozen
isn't necessary.
PS, is there an automated way of testing this sort of thing? I just ran |
Unfortunately there is no way to automatically test. |
If that's the case, I'm not sure why Travis failed, as it seems a bit unrelated. |
The failure is unrelated. I restarted travis |
else: | ||
continue | ||
|
||
a.set_view_from_bbox((lastx, lasty, x, y), view, direction, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this view
variable is not defined
34d0143
to
88afb19
Compare
@QuLogic Did you try it with |
I've been working on it here. It's a bit hacky and some things are buggy, but the API here seems to work well enough. |
👍 |
@OceanWolf @tacaswell what do you guys think? |
Sorry, I have my hands full else where and have not been paying attention to this thread at all. |
Attn: @mdboom, @pelson: this is important, and I think it deals with On 8/1/15, Thomas A Caswell notifications@github.com wrote:
|
Thanks @efiring. The proposal makes a lot of sense - 👍 on the axes being able to control what and how the "view" is preserved. My only concerns are about:
Otherwise, awesome contribution @QuLogic, thanks! |
@pelson I actually prefer the public methods, they allow to easily switch views programatically. |
Completely. But imagine you were coming to mpl for the first time: there are already way to many public methods. This functionality is superb, and I know it will be well used by cartopy for one, but it isn't in the list of the first 30 methods on an Axes I'd show to a new user... Alternatively, @shoyer and I talked about the concept of method namespaces such that you could do something like |
@pelson Long term I would like to pull all of the plotting methods off of the I really need to write up a long document of my thoughts on large-scale API changes. |
Custom Axes may require additional information than simply the x/y limits to describe the view. This API will allow the navigation buttons on the toolbar to function correctly with such Axes.
The main benefit here will be PolarAxes, but there might be other custom Axes that find this useful.
88afb19
to
7e582b1
Compare
Think of it this way: there were two copies in the two toolbars, and now there's only one copy in the axes, so I've reduced code redundancy! |
I seem to always get this PS backend failure... |
Is anybody against this? |
ENH: Add API to manage view state in custom Axes.
@QuLogic - thanks for this awesome change 👍. |
I'm pretty sure this is in the rc for 1.5, though it's tagged as 2.1. |
@QuLogic Yes if you click a commit you can see which tags it's in. Both of these are in 1.5 rc1 |
Oh yes, I know; I just like to keep my milestones straight. |
Sorry for those just messaged, hit reply to wrong email, just delete. |
Custom
Axes
may require additional information than simply the x/y-limits to describe the view. This API will allow the navigation buttons on the toolbar to function correctly with suchAxes
(but not necessarily the zoom or pan buttons just yet.)This PR is simply a quick-to-implement idea; I have not yet applied it anywhere, though the intended usage is in
PolarAxes
, of course. From discussions on #4699, it seems like something like this might be useful for mplot3d as well.There's also the question of how to update the view. As we all know by now, setting the x/y-limits does not work if the axes are not Cartesian. But
NavigationToolbar2.release_zoom
does quite a bit of other stuff before setting the limits and I'm not sure how to reconcile this at the moment.