@@ -2592,7 +2592,7 @@ def scroll_handler(event, canvas=None, toolbar=None):
2592
2592
# is required for interactive navigation.
2593
2593
return
2594
2594
2595
- if event .key == "control" : # zoom towards the mouse position
2595
+ if event .key in { "control" , "x" , "y" } : # zoom towards the mouse position
2596
2596
toolbar .push_current ()
2597
2597
2598
2598
xmin , xmax = ax .get_xlim ()
@@ -2604,10 +2604,21 @@ def scroll_handler(event, canvas=None, toolbar=None):
2604
2604
x , y = ax .transScale .transform ((event .xdata , event .ydata ))
2605
2605
2606
2606
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
2611
2622
2612
2623
inv_scale = ax .transScale .inverted ()
2613
2624
(new_xmin , new_ymin ), (new_xmax , new_ymax ) = inv_scale .transform (
0 commit comments