title: How to adjust panning while zooming
body: <p>I want to pan while zooming into a Mandelbrot set so that the fractal portion of the function stays within the window. The code outputs a series of png images to later be made into a video. Right now, I have the zooming and panning working but I do not know how to adjust the panning while the function is zooming.  </p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  from os import path
  
  #6:36 @2560x1440 500 iter
  #2:51 @2560x1440 200 iter
  #0:56 @2560x1440 50 iter
  #1:35 @2560x1440 100 iter
  #0:53 @1920x1080 100 iter
  #0:24 @1280x720  100 iter -&gt; run overnight to generate 1000pngs
  #make a video out of images in blender
  
  #resolution
  col=720
  rows=1280
  
  #initial window
  x1=0.24#-0.78#-2#this initial window captures the whole Mandelbrot
  x2=0.39#-0.73#1
  y1=-0.1#0.03#-1
  y2=0.08#0.13#1
  #DON'T FORGET TO CHANGE THE OUTPATH!!!
  outpath='C:\Users\yourfilepath\Seahorse valley'
  #run at n=1000 overnight
  for k in range(3): #generates n images (WARNING: this can take a while for n&gt;5 at high res)
      zoom=0.1
      def mandelbrot(x,c,maxiter):
          c=complex(x,c) #x+ci
          z=0.0j #j is python for imaginary numbers (i)
  
          for i in range(maxiter):
             z=z**2+c #change power of z to generate other epicycloids 
             if(z.real*z.real+z.imag*z.imag)&gt;=4:
                 return i
          return maxiter
  
      result=np.zeros([rows,col])
      for rowindex, x in enumerate(np.linspace(x1,x2,num=rows)):
          for colindex, c in enumerate(np.linspace(y1,y2,num=col)):
              result[rowindex,colindex]=mandelbrot(x,c,40)
  
      plt.figure()
      plt.imshow(result.T, cmap='jet_r') #[x1,x2,y1,y2])
      plt.title('Mandelbrot')
      plt.xlabel('Real C')
      plt.ylabel('Complex C')
      plt.savefig(path.join(outpath,'Seahorse {0}.png'.format(k)),dpi=1000)
  
      #zooms in for the next image.
      x1=x1+zoom #Change the zoom per iteration
      x2=x2-zoom #changing individial values allows for panning
      y1=y1+zoom #need to figure out how to adjust pan to stay on fractal
      y2=y2-zoom
      zoom+=zoom/2
  
  #elephant valley coordinates in here
  #(0.24,0.39,num=rows)
  #(-0.1,0.08,num=col)
  
  #coords for seahorse valley
  #(-0.78,-0.73,num=rows)
  #(0.03,0.13,num=col)
  </code></pre>
  
  <p>I can zoom and pan, but how do I automate the panning to stay focused on the fractal? I want to run this code while I am sleeping.</p>