Skip to content

Add zoom_factory to matplotlib - where to put? #18159

Closed

Description

@ianhi

@tacaswell wrote a zoom_factory function that enables zooming with the mouse scroll wheel in this gist: https://gist.github.com/tacaswell/3144287 this is very useful and would be great if it was offered as a utility function by matplotlib. In mpl-extensions/mpl-interactions#21 (comment) tacaswell wrote:

I am 👍 on a PR to core Matplotlib to add that factory (not sure where) as it is useful in all backends (not just ipympl).

So this issue is to discuss whether/where to incorporate the zoom_factory function. Two initial suggestions:

  1. in the toolbar
  2. in pyplot
    • Architecturally I don't think this makes as much sense but as a user I don't think I would expect to look at the toolbar for utility methods

Additionally I forked that gist (https://gist.github.com/ianhi/b638e09fa7a00764ea539940a0519af9) and added two things:

  1. push initial position to toolbar navstack so the home button works as expected
  2. automatic centering when zoomed out past initial bounds
    • This could be made optional

if this were to be incorporated in matplotlib it would be nice to have those features as well.

Here is a gif of this with with some extra code to allow middle click to pan(https://gist.github.com/ianhi/5f514c31f13cc28fbd167849867122b7):

Activity

  1. added this to the v3.4.0 milestone on Aug 3, 2020
  2. tacaswell commented on Aug 3, 2020

    @tacaswell
    Member

    It should not go in pyplot as we want this available to people who avoid the global state tracking of pyplot.

    This should probably go in https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/backend_tools.py and target the MEP22 style toolbars. I suspect that we would want to have this enabled by default on the zoom tool?

  3. ianhi commented on Aug 3, 2020

    @ianhi
    ContributorAuthor

    I suspect that we would want to have this enabled by default on the zoom tool?

    Do you mean on zoom to rect? I think that adding this to the panning mode feels the most natural:
    image

    though it will be good to keep this available outside of a toolbar button to allow greater control. For instance I use this with middle click to pan and left click to use the lasso tool.

  4. modified the milestones: v3.4.0, v3.5.0 on Jan 27, 2021
  5. ianhi commented on Jun 17, 2021

    @ianhi
    ContributorAuthor

    This would be fixed by #20317

  6. modified the milestones: v3.5.0, v3.6.0 on Sep 25, 2021
  7. modified the milestones: v3.6.0, v3.7.0 on Jul 8, 2022
  8. github-actions commented on Mar 16, 2026

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  9. timhoffm commented on Mar 16, 2026

    @timhoffm
    Member

    Fixed by #30405.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions