title: Matplotlib error message: "TypeError: 'Ellipse' object is not iterable"
body: <p>I tried to run an animation within matplotlib (Python) animate and I got the error</p>
  
  <pre><code>TypeError: 'Ellipse' object is not iterable
  </code></pre>
  
  <p>Ellipse is an object of type "patches" ... </p>
  
  <p>the result being:</p>
  
  <p><a href="https://i.stack.imgur.com/skEBk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/skEBk.png" alt="this is the interim result from the code sample"></a></p>
  
  <p>The program runs and produces the first subplot - it should move the ellipse along the read "line" .. however produced the above error message . </p>
  
  <p>Now what does the error-message mean.</p>
  
  <pre><code># -*- coding: utf-8 -*-
  #############################################################################
  #   first try to compute the program for demonstrating the dependency of
  #   total annual insolation of a planet (here Earth) on the ellipticity of 
  #   the orbit
  #
  #############################################################################
  #   created 2015-06-01 by Jörg Kampmann - IBK-consult - D-31228 Peine
  #
  #############################################################################
  #   the insolation 
  #   N_EGA = (2*pi**2*R**2*N0)/(n*a**2*sqrt(1 - e**2))
  #   is dependent on "e" under the assumption that "a" and "N0" are constant
  #
  #   this module 
  #   computes and shows presently the dependency of TOI over e
  #
  #   Todo: animation of size of ellipse when eccentricity grows from zero to 
  #   ECCmax
  #
  #############################################################################
  #Path to the workbook datasets
  #datapath = '/home/kampmann/rtpSW/WorkbookDatasets/'
  #Path to the hitran by-molecule database
  #hitranPath = datapath+'Chapter4Data/hitran/ByMolecule/'
  
  """
  Excentricity is ECC = sqrt(a**2 - b**2) or
  ECC**2 = a**2 - b**2
  b**2 = a**2 - ECC**2
  b = sqrt(a**2 - ECC**2)
  a = height/2.0
  -&gt;
  b = sqrt(height**2/4.0 - ECC**2)
  """
  
  import math
  from ClimateUtilities import *
  import phys
  import numpy as nm
  import matplotlib.animation as animation
  import matplotlib.pyplot as plt
  from matplotlib import patches
  #from matplotlib import animation
  
  
  #------------Constants and file data------------
  # eccentricity
  printswitch = True
  printswitch = False
  printswitch2 = True
  #printswitch2 = False
  
  ECCabsoluteMax = 0.9
  ECCmax = 0.067      # maximum value for this run - should not be greater than
                      # ECCabsoluteMax
  #ECCmax = 0.9      # maximum value for this run - should not be greater than
                      # ECCabsoluteMax
  if ECCmax &gt;= ECCabsoluteMax: 
      ECCmax = ECCabsoluteMax
  
  ECCdelta = 0.001    # interval for graph
  
  eccentricity = nm.arange(0., ECCmax, ECCdelta, dtype=float)
  semimajorA = 1.0        # astronomical unit =~ 150.000.000 km mean distance Sun Earth
  totalRadN0 = 1370.      # radiation of Sun at TOA in Watt/m**2
  albedoEarth = 0.3       # presently albedo of Earth, geographically constant
  T = 365.25              # duration of one orbit around central celestial body in days
                          # here: duration of one orbit of Earth around Sun
  R = 6378100.0           # radius of Earth in meters
  
  TOIdim = ECCmax/ECCdelta
  TOI =nm.arange(0., TOIdim, dtype=float ) 
                          # total insolation at location of Earth summed over 1 year
  
  """
  now define various "functions" like:
  """
  def computeTOI( ee, semimajorAxis, radiationAtStar, alpha  ):
  
      aa = semimajorAxis  # semimajor axis of orbital ellipse
      N0 = radiationAtStar# radiation of start at position of star (r = 0)
      resultTOI = 2.*nm.pi*T*R**2*N0*alpha/(aa**2*math.sqrt(1 - ee**2))
      return resultTOI
  
  def init_TOI():
      line1.set_data([], [])
      return line1
  
  def init_Ellipse():
      line2.set_data([], [])
      return line2
  
  def animateTOI():
  
      return True
  #
  #####################################################################
  #
  print "start of ellipticity and absorbed insolation"
  #
  #
  # Start of programme here
  #
  #####################################################################
  
  # compute the various TOIs dependant on eccentricity "ecc"
  #
  ii = 0
  for ecc in eccentricity:
      if printswitch:   print 'TOI = ', computeTOI( ecc, semimajorA, totalRadN0, albedoEarth ), '\n'
      TOI[ii] = computeTOI( ecc, semimajorA, totalRadN0, 1. - albedoEarth )/10.0**19
      ii = ii + 1
  
  # TOI is an array consisting of TOIs depending on eccemtricity "ecc" 
  
  x = eccentricity
  if printswitch: print 'TOI = ', TOI
  
  #print 'ECC = ', x
  
  # almost the whole screen is filled with this plot ... :)
  Main = plt.figure(figsize=(15.0,15.0))  
  Main.subplots_adjust(top=0.95, left=0.09, right=0.95, hspace=0.20)
  
  axFigTOI = Main.add_subplot(211)
  
  # Plot ... TOI over ECC: 
  
  if ECCmax &lt; 0.07: 
      plt.axis([0,0.07,8.9,9.0]) 
  
  plt.title( 'Absorbed Irradiation and Orbital Eccentricity for Planet Earth\n' )
  plt.ylabel( 'Absorbed total \nsolar irradiation \n[Watt] *10**19' )
  plt.xlabel( 'Eccentricity "e"' )
  
  plt.plot( x, TOI, 'r-' )  # this works fine! 'x' and 'TOI' are center of mini-ellipse
  
  # Now enter an ellipse here on Subplot 211:
  
  xcenter, ycenter = x[1],TOI[1]      # center of ellipse to start with
  width = 0.0025
  height = 0.01
  
  
  e1 = patches.Ellipse((xcenter, ycenter), width, height,\
              angle=0.0, linewidth=2, fill=True, zorder=2)
  e1.set_visible(True)
  axFigTOI.add_patch( e1 )
  
  def init():
      axFigTOI.add_patch(e1)
      return e1
  
  def animateEllipse(i):
  
      xcenter = x[i]
      ycenter = TOI[i]
      e1 = patches.Ellipse((xcenter, ycenter), width, height,\
               angle=0.0, linewidth=2, fill=True, zorder=2)
      if i == 1:
          e1.set_visible(True)
  
      axFigTOI.add_patch(e1)
  
      return e1
  
  anim = animation.FuncAnimation(Main, animateEllipse, 
                                 init_func=init, 
                                 frames=360, 
                                 interval=20,
                                 blit=True)
  
  plt.show()
  
  
  
  
  
  ---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  /home/kampmann/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/matplotlib/backends/backend_qt5.pyc in resizeEvent(self=&lt;matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg object&gt;, event=&lt;0xbf9f7b48 &gt;)
      336         self.figure.set_size_inches(winch, hinch)
      337         FigureCanvasBase.resize_event(self)
  --&gt; 338         self.draw()
          self.draw = &lt;bound method FigureCanvasQTAgg.draw of &lt;matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg object at 0xb0eef26c&gt;&gt;
      339         self.update()
      340         QtWidgets.QWidget.resizeEvent(self, event)
  
  /home/kampmann/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/matplotlib/backends/backend_qt5agg.pyc in draw(self=&lt;matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg object&gt;)
      146         # causes problems with code that uses the result of the
      147         # draw() to update plot elements.
  --&gt; 148         FigureCanvasAgg.draw(self)
          global FigureCanvasAgg.draw = &lt;unbound method FigureCanvasAgg.draw&gt;
          self = &lt;matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg object at 0xb0eef26c&gt;
      149         self._priv_update()
      150 
  
  /home/kampmann/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in draw(self=&lt;matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg object&gt;)
      467 
      468         try:
  --&gt; 469             self.figure.draw(self.renderer)
          self.figure.draw = &lt;bound method Figure.draw of &lt;matplotlib.figure.Figure object at 0xb100896c&gt;&gt;
          self.renderer = &lt;matplotlib.backends.backend_agg.RendererAgg object at 0xb117bbec&gt;
      470         finally:
      471             RendererAgg.lock.release()
  
  /home/kampmann/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist=&lt;matplotlib.figure.Figure object&gt;, renderer=&lt;matplotlib.backends.backend_agg.RendererAgg object&gt;, *args=(), **kwargs={})
       57     def draw_wrapper(artist, renderer, *args, **kwargs):
       58         before(artist, renderer)
  ---&gt; 59         draw(artist, renderer, *args, **kwargs)
          global draw = undefined
          artist = &lt;matplotlib.figure.Figure object at 0xb100896c&gt;
          renderer = &lt;matplotlib.backends.backend_agg.RendererAgg object at 0xb117bbec&gt;
          args = ()
          kwargs = {}
       60         after(artist, renderer)
       61 
  
  /home/kampmann/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/matplotlib/figure.pyc in draw(self=&lt;matplotlib.figure.Figure object&gt;, renderer=&lt;matplotlib.backends.backend_agg.RendererAgg object&gt;)
     1089         self._cachedRenderer = renderer
     1090 
  -&gt; 1091         self.canvas.draw_event(renderer)
          self.canvas.draw_event = &lt;bound method FigureCanvasQTAgg.draw_event of &lt;matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg object at 0xb0eef26c&gt;&gt;
          renderer = &lt;matplotlib.backends.backend_agg.RendererAgg object at 0xb117bbec&gt;
     1092 
     1093     def draw_artist(self, a):
  
  /home/kampmann/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in draw_event(self=&lt;matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg object&gt;, renderer=&lt;matplotlib.backends.backend_agg.RendererAgg object&gt;)
     1793         s = 'draw_event'
     1794         event = DrawEvent(s, self, renderer)
  -&gt; 1795         self.callbacks.process(s, event)
          self.callbacks.process = &lt;bound method CallbackRegistry.process of &lt;matplotlib.cbook.CallbackRegistry instance at 0xb0e3814c&gt;&gt;
          s = u'draw_event'
          event = &lt;matplotlib.backend_bases.DrawEvent instance at 0xb0ebebac&gt;
     1796 
     1797     def resize_event(self):
  
  /home/kampmann/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/matplotlib/cbook.pyc in process(self=&lt;matplotlib.cbook.CallbackRegistry instance&gt;, s=u'draw_event', *args=(&lt;matplotlib.backend_bases.DrawEvent instance&gt;,), **kwargs={})
      538                     del self.callbacks[s][cid]
      539                 else:
  --&gt; 540                     proxy(*args, **kwargs)
          proxy = &lt;matplotlib.cbook._BoundMethodProxy object at 0xb0fdfb2c&gt;
          args = (&lt;matplotlib.backend_bases.DrawEvent instance at 0xb0ebebac&gt;,)
          kwargs = {}
      541 
      542 
  
  /home/kampmann/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/matplotlib/cbook.pyc in __call__(self=&lt;matplotlib.cbook._BoundMethodProxy object&gt;, *args=(&lt;matplotlib.backend_bases.DrawEvent instance&gt;,), **kwargs={})
      413             mtd = self.func
      414         # invoke the callable and return the result
  --&gt; 415         return mtd(*args, **kwargs)
          mtd = &lt;bound method ?._end_redraw of &lt;matplotlib.animation.FuncAnimation object at 0xb0fdf44c&gt;&gt;
          args = (&lt;matplotlib.backend_bases.DrawEvent instance at 0xb0ebebac&gt;,)
          kwargs = {}
      416 
      417     def __eq__(self, other):
  
  /home/kampmann/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/matplotlib/animation.pyc in _end_redraw(self=&lt;matplotlib.animation.FuncAnimation object&gt;, evt=&lt;matplotlib.backend_bases.DrawEvent instance&gt;)
      879         # Now that the redraw has happened, do the post draw flushing and
      880         # blit handling. Then re-enable all of the original events.
  --&gt; 881         self._post_draw(None, self._blit)
          self._post_draw = &lt;bound method FuncAnimation._post_draw of &lt;matplotlib.animation.FuncAnimation object at 0xb0fdf44c&gt;&gt;
          global None = undefined
          self._blit = True
      882         self.event_source.start()
      883         self._fig.canvas.mpl_disconnect(self._resize_id)
  
  /home/kampmann/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/matplotlib/animation.pyc in _post_draw(self=&lt;matplotlib.animation.FuncAnimation object&gt;, framedata=None, blit=True)
      825         # blitting.
      826         if blit and self._drawn_artists:
  --&gt; 827             self._blit_draw(self._drawn_artists, self._blit_cache)
          self._blit_draw = &lt;bound method FuncAnimation._blit_draw of &lt;matplotlib.animation.FuncAnimation object at 0xb0fdf44c&gt;&gt;
          self._drawn_artists = &lt;matplotlib.patches.Ellipse object at 0xb0fdf80c&gt;
          self._blit_cache = {}
      828         else:
      829             self._fig.canvas.draw_idle()
  
  /home/kampmann/Enthought/Canopy_32bit/User/lib/python2.7/site-packages/matplotlib/animation.pyc in _blit_draw(self=&lt;matplotlib.animation.FuncAnimation object&gt;, artists=&lt;matplotlib.patches.Ellipse object&gt;, bg_cache={})
      834         # of the entire figure.
      835         updated_ax = []
  --&gt; 836         for a in artists:
          a = undefined
          artists = &lt;matplotlib.patches.Ellipse object at 0xb0fdf80c&gt;
      837             # If we haven't cached the background for this axes object, do
      838             # so now. This might not always be reliable, but it's an attempt
  
  TypeError: 'Ellipse' object is not iterable
  </code></pre>