Skip to content

ENH: Add pan and zoom toolbar handling to 3D Axes #22614

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

Closed
wants to merge 1 commit into from

Conversation

greglucas
Copy link
Contributor

PR Summary

This enables the toolbar buttons to work with 3D axes now. The panning works pretty seamlessly, but the zooming is perhaps not the easiest to use still. This is because it is zooming based on relative locations between the selected box and the Axes, but the Axes actually expands beyond the corners seen in the 3D grid world. If you zoom using the x/y keys to constrain the axes, you will see that the zoom box actually goes a ways outside the 3D world, and then behaves quite well when constrained like that from an intuitive sense. I'm open to suggestions here if anyone can think of a better way to implement the zoom logic, or if we think it is still a bit too complicated and that tool should not be implemented at all.

Test with any of the 3D examples:
https://matplotlib.org/stable/gallery/mplot3d/surface3d.html
https://matplotlib.org/stable/gallery/mplot3d/scatter3d.html

Commit summary:

This moves the pan logic that was already in the mouse move handler
into the "drag_pan" method to make it available from the toolbar.

This also expands upon the panning logic to enable a zoom-to-box feature.
The zoom-to-box is done relative to the Axes, so it shrinks/expands
the box as a fraction of each delta, from lower-left Axes to lower-left
zoom-box. Thus, it tries to handle non-centered zooms, which adds more
cases to handle versus the current right-click zoom only scaling from
the center of the projection.

Closes #110

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • [] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@greglucas greglucas added this to the v3.6.0 milestone Mar 6, 2022
1) This moves the pan logic that was already in the mouse move handler
into the "drag_pan" method to make it available from the toolbar.

2) This expands upon the panning logic to enable a zoom-to-box feature.
The zoom-to-box is done relative to the Axes, so it shrinks/expands
the box as a fraction of each delta, from lower-left Axes to lower-left
zoom-box. Thus, it tries to handle non-centered zooms, which adds more
cases to handle versus the current right-click zoom only scaling from
the center of the projection.
@scottshambaugh
Copy link
Contributor

Tried this out today. Something feels off, consider the behavior when I try to zoom in on the corner of this box, and the area I'm zooming in on goes out of frame.
image
image

If I zoom out by deselecting the zoom button and using the right mouse button, I see that the data aspect ratio has changed, which I don't think it should for a near-square zoom box.
image

Don't have time to dig into the logic right now, but that should hopefully give something to dig into here.

@greglucas
Copy link
Contributor Author

@scottshambaugh, I think this is likely due to selecting x/y/z coordinates from the 2d-x'y' plane and setting the limits based on those. (i.e. where in depth do those coordinates come from and what depth do we want to use to set the x/y/z limits for the axes?) I agree with you, this is not super ideal as it is currently. Maybe we should just remove the zoom box capability and leave it at pan which I think works better in these cases.

This was a rough attempt a while ago, so I don't have a lot of interest in pushing it through right now. Please feel free to take this over if you have the time/desire!

@timhoffm
Copy link
Member

@scottshambaugh Thanks for testing this PR!

@deeleeramone
Copy link

Greetings, unfortunately, without the canvas layer locking with the zoom, the charts are unusable.

Screen Shot 2022-07-16 at 8 36 39 PM

@scottshambaugh
Copy link
Contributor

I’m taking a stab at this, more to come soon.

@deeleeramone
Copy link

deeleeramone commented Jul 17, 2022 via email

@greglucas
Copy link
Contributor Author

greglucas commented Jul 29, 2022

superseded by #23449

@greglucas greglucas closed this Jul 29, 2022
@QuLogic QuLogic modified the milestones: v3.6.0, v3.7.0 Sep 9, 2022
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.

pan and zoom are broken for mplot3d
6 participants