Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8262233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:41:51+00:00 2026-06-08T03:41:51+00:00

Is it possible to bind the scroll wheel to zoom in/out when the cursor

  • 0

Is it possible to bind the scroll wheel to zoom in/out when the cursor is hovering over a matplotlib plot?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T03:41:52+00:00Added an answer on June 8, 2026 at 3:41 am

    This should work. It re-centers the graph on the location of the pointer when you scroll.

    import matplotlib.pyplot as plt
    
    
    def zoom_factory(ax,base_scale = 2.):
        def zoom_fun(event):
            # get the current x and y limits
            cur_xlim = ax.get_xlim()
            cur_ylim = ax.get_ylim()
            cur_xrange = (cur_xlim[1] - cur_xlim[0])*.5
            cur_yrange = (cur_ylim[1] - cur_ylim[0])*.5
            xdata = event.xdata # get event x location
            ydata = event.ydata # get event y location
            if event.button == 'up':
                # deal with zoom in
                scale_factor = 1/base_scale
            elif event.button == 'down':
                # deal with zoom out
                scale_factor = base_scale
            else:
                # deal with something that should never happen
                scale_factor = 1
                print event.button
            # set new limits
            ax.set_xlim([xdata - cur_xrange*scale_factor,
                         xdata + cur_xrange*scale_factor])
            ax.set_ylim([ydata - cur_yrange*scale_factor,
                         ydata + cur_yrange*scale_factor])
            plt.draw() # force re-draw
    
        fig = ax.get_figure() # get the figure of interest
        # attach the call back
        fig.canvas.mpl_connect('scroll_event',zoom_fun)
    
        #return the function
        return zoom_fun
    

    Assuming you have an axis object ax

     ax.plot(range(10))
     scale = 1.5
     f = zoom_factory(ax,base_scale = scale)
    

    The optional argument base_scale allows you to set the scale factor to be what ever you want.

    make sure you keep a copy of f around. The call back uses a weak-ref so if you do not keep a copy of f it might be garbage collected.

    After writing this answer I decided this actually quite useful and put it in a gist

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Bind multiple events to jQuery 'live' method I have the following function:
Is it possible to bind to a property of a property? Here is what
would it be possible to bind a Java application to a Cocoa graphical interface?
Is it possible to bind/rebind a RadListView's datasource using Ajax? What I'm trying to
Is it possible to bind the current item to a tag in button from
Trying to determine if it is possible to bind the SelectedValue of a ComboBox
How is it possible to make knockout data-bind work on dynamically generated elements? For
Is it possible in WPF to bind a ListView (NOT a DataGrid) to a
Is it possible with only one bind to either keyup , keypress or keydown
Is it possible to add a dependency property to a ValueConverter and bind it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.