@@ -2592,7 +2592,7 @@ def scroll_handler(event, canvas=None, toolbar=None):
25922592 # is required for interactive navigation.
25932593 return
25942594
2595- if event .key == "control" : # zoom towards the mouse position
2595+ if event .key in { "control" , "x" , "y" } : # zoom towards the mouse position
25962596 toolbar .push_current ()
25972597
25982598 xmin , xmax = ax .get_xlim ()
@@ -2604,10 +2604,21 @@ def scroll_handler(event, canvas=None, toolbar=None):
26042604 x , y = ax .transScale .transform ((event .xdata , event .ydata ))
26052605
26062606 scale_factor = 0.85 ** event .step
2607- new_xmin = x - (x - xmin ) * scale_factor
2608- new_xmax = x + (xmax - x ) * scale_factor
2609- new_ymin = y - (y - ymin ) * scale_factor
2610- new_ymax = y + (ymax - y ) * scale_factor
2607+ # Determine which axes to scale based on key
2608+ zoom_x = event .key in {"control" , "x" }
2609+ zoom_y = event .key in {"control" , "y" }
2610+
2611+ if zoom_x :
2612+ new_xmin = x - (x - xmin ) * scale_factor
2613+ new_xmax = x + (xmax - x ) * scale_factor
2614+ else :
2615+ new_xmin , new_xmax = xmin , xmax
2616+
2617+ if zoom_y :
2618+ new_ymin = y - (y - ymin ) * scale_factor
2619+ new_ymax = y + (ymax - y ) * scale_factor
2620+ else :
2621+ new_ymin , new_ymax = ymin , ymax
26112622
26122623 inv_scale = ax .transScale .inverted ()
26132624 (new_xmin , new_ymin ), (new_xmax , new_ymax ) = inv_scale .transform (
0 commit comments