@@ -3137,7 +3137,7 @@ def zoom(self, *args):
3137
3137
a .set_navigate_mode (self .mode ._navigate_mode )
3138
3138
self .set_message (self .mode )
3139
3139
3140
- _ZoomInfo = namedtuple ("_ZoomInfo" , "direction start_xy axes cid" )
3140
+ _ZoomInfo = namedtuple ("_ZoomInfo" , "direction start_xy axes cid cbar " )
3141
3141
3142
3142
def press_zoom (self , event ):
3143
3143
"""Callback for mouse button press in zoom to rect mode."""
@@ -3152,29 +3152,34 @@ def press_zoom(self, event):
3152
3152
self .push_current () # set the home button to this view
3153
3153
id_zoom = self .canvas .mpl_connect (
3154
3154
"motion_notify_event" , self .drag_zoom )
3155
+ # A colorbar is one-dimensional, so we extend the zoom rectangle out
3156
+ # to the edge of the axes bbox in the other dimension. To do that we
3157
+ # store the orientation of the colorbar for later.
3158
+ if hasattr (axes [0 ], "_colorbar" ):
3159
+ cbar = axes [0 ]._colorbar .orientation
3160
+ else :
3161
+ cbar = None
3155
3162
self ._zoom_info = self ._ZoomInfo (
3156
3163
direction = "in" if event .button == 1 else "out" ,
3157
- start_xy = (event .x , event .y ), axes = axes , cid = id_zoom )
3164
+ start_xy = (event .x , event .y ), axes = axes , cid = id_zoom , cbar = cbar )
3158
3165
3159
3166
def drag_zoom (self , event ):
3160
3167
"""Callback for dragging in zoom mode."""
3161
3168
start_xy = self ._zoom_info .start_xy
3162
3169
ax = self ._zoom_info .axes [0 ]
3163
3170
(x1 , y1 ), (x2 , y2 ) = np .clip (
3164
3171
[start_xy , [event .x , event .y ]], ax .bbox .min , ax .bbox .max )
3165
- if event .key == "x" :
3172
+ key = event .key
3173
+ # Force the key on colorbars to extend the short-axis bbox
3174
+ if self ._zoom_info .cbar == "horizontal" :
3175
+ key = "x"
3176
+ elif self ._zoom_info .cbar == "vertical" :
3177
+ key = "y"
3178
+ if key == "x" :
3166
3179
y1 , y2 = ax .bbox .intervaly
3167
- elif event . key == "y" :
3180
+ elif key == "y" :
3168
3181
x1 , x2 = ax .bbox .intervalx
3169
3182
3170
- # A colorbar is one-dimensional, so we extend the zoom rectangle out
3171
- # to the edge of the axes bbox in the other dimension
3172
- if hasattr (ax , "_colorbar" ):
3173
- if ax ._colorbar .orientation == 'horizontal' :
3174
- y1 , y2 = ax .bbox .intervaly
3175
- else :
3176
- x1 , x2 = ax .bbox .intervalx
3177
-
3178
3183
self .draw_rubberband (event , x1 , y1 , x2 , y2 )
3179
3184
3180
3185
def release_zoom (self , event ):
@@ -3188,10 +3193,17 @@ def release_zoom(self, event):
3188
3193
self .remove_rubberband ()
3189
3194
3190
3195
start_x , start_y = self ._zoom_info .start_xy
3196
+ key = event .key
3197
+ # Force the key on colorbars to ignore the zoom-cancel on the
3198
+ # short-axis side
3199
+ if self ._zoom_info .cbar == "horizontal" :
3200
+ key = "x"
3201
+ elif self ._zoom_info .cbar == "vertical" :
3202
+ key = "y"
3191
3203
# Ignore single clicks: 5 pixels is a threshold that allows the user to
3192
3204
# "cancel" a zoom action by zooming by less than 5 pixels.
3193
- if ((abs (event .x - start_x ) < 5 and event . key != "y" )
3194
- or (abs (event .y - start_y ) < 5 and event . key != "x" )):
3205
+ if ((abs (event .x - start_x ) < 5 and key != "y" ) or
3206
+ (abs (event .y - start_y ) < 5 and key != "x" )):
3195
3207
self .canvas .draw_idle ()
3196
3208
self ._zoom_info = None
3197
3209
return
@@ -3205,7 +3217,7 @@ def release_zoom(self, event):
3205
3217
for prev in self ._zoom_info .axes [:i ])
3206
3218
ax ._set_view_from_bbox (
3207
3219
(start_x , start_y , event .x , event .y ),
3208
- self ._zoom_info .direction , event . key , twinx , twiny )
3220
+ self ._zoom_info .direction , key , twinx , twiny )
3209
3221
3210
3222
self .canvas .draw_idle ()
3211
3223
self ._zoom_info = None
0 commit comments