@@ -31,7 +31,7 @@ def __init__(self, h=500, w=500, niter=50, radius=2., power=2):
3131 self .radius = radius
3232 self .power = power
3333
34- def __call__ (self , xstart , xend , ystart , yend ):
34+ def compute_image (self , xstart , xend , ystart , yend ):
3535 self .x = np .linspace (xstart , xend , self .width )
3636 self .y = np .linspace (ystart , yend , self .height ).reshape (- 1 , 1 )
3737 c = self .x + 1.0j * self .y
@@ -46,25 +46,21 @@ def __call__(self, xstart, xend, ystart, yend):
4646
4747 def ax_update (self , ax ):
4848 ax .set_autoscale_on (False ) # Otherwise, infinite loop
49-
5049 # Get the number of points from the number of pixels in the window
51- dims = ax .patch .get_window_extent ().bounds
52- self .width = int (dims [2 ] + 0.5 )
53- self .height = int (dims [2 ] + 0.5 )
54-
50+ self .width , self .height = \
51+ np .round (ax .patch .get_window_extent ().size ).astype (int )
5552 # Get the range for the new area
56- xstart , ystart , xdelta , ydelta = ax .viewLim .bounds
57- xend = xstart + xdelta
58- yend = ystart + ydelta
59-
53+ vl = ax .viewLim
54+ extent = vl .x0 , vl .x1 , vl .y0 , vl .y1
6055 # Update the image object with our new data and extent
6156 im = ax .images [- 1 ]
62- im .set_data (self .__call__ ( xstart , xend , ystart , yend ))
63- im .set_extent (( xstart , xend , ystart , yend ) )
57+ im .set_data (self .compute_image ( * extent ))
58+ im .set_extent (extent )
6459 ax .figure .canvas .draw_idle ()
6560
61+
6662md = MandelbrotDisplay ()
67- Z = md (- 2. , 0.5 , - 1.25 , 1.25 )
63+ Z = md . compute_image (- 2. , 0.5 , - 1.25 , 1.25 )
6864
6965fig1 , (ax1 , ax2 ) = plt .subplots (1 , 2 )
7066ax1 .imshow (Z , origin = 'lower' ,
0 commit comments