@@ -132,7 +132,7 @@ def __init__(self, plotCanvas, multPlots=False, allowselect=False):
132
132
133
133
self .msg = wx .StaticText (self , - 1 , "" )
134
134
self .AddControl (self .msg )
135
-
135
+ self . canvas . mpl_connect ( 'scroll_event' , self . on_scroll_zoom )
136
136
self .Realize ()
137
137
138
138
def editSeries (self , xys , edit ):
@@ -248,6 +248,8 @@ def on_toggle_zoom_data_tool(self, event):
248
248
self .canvas .draw ()
249
249
250
250
251
+
252
+
251
253
#must add these methods for mac functionality
252
254
def release_zoom (self , event ):
253
255
super (self .__class__ , self ).release_zoom (event )
@@ -264,3 +266,37 @@ def forward(self, event):
264
266
def home (self , event ):
265
267
super (self .__class__ , self ).home (event )
266
268
self .canvas .draw ()
269
+
270
+
271
+
272
+
273
+ def on_scroll_zoom (self , event ):
274
+ axes = self .canvas .figure .axes [0 ]
275
+ base_scale = 1.2
276
+ # get the current x and y limits
277
+ cur_xlim = axes .get_xlim ()
278
+ cur_ylim = axes .get_ylim ()
279
+ cur_xrange = (cur_xlim [1 ] - cur_xlim [0 ])* .5
280
+ cur_yrange = (cur_ylim [1 ] - cur_ylim [0 ])* .5
281
+ xdata = event .xdata # get event x location
282
+ ydata = event .ydata # get event y location
283
+ if event .button == 'up' :
284
+ # deal with zoom in
285
+ scale_factor = 1 / base_scale
286
+ elif event .button == 'down' :
287
+ # deal with zoom out
288
+ scale_factor = base_scale
289
+ else :
290
+ # deal with something that should never happen
291
+ scale_factor = 1
292
+ print event .button
293
+ # set new limits
294
+ axes .set_xlim ([xdata - cur_xrange * scale_factor ,
295
+ xdata + cur_xrange * scale_factor ])
296
+ axes .set_ylim ([ydata - cur_yrange * scale_factor ,
297
+ ydata + cur_yrange * scale_factor ])
298
+ self .canvas .draw () # force re-draw
299
+
300
+ # fig = ax.get_figure() # get the figure of interest
301
+ # attach the call back
302
+
0 commit comments