title: matplotlib: "TypeError: Image data can not convert to float" for what look like a fine matrix
body: <p>I know that other people are seeing similar errors (<a href="https://stackoverflow.com/questions/32302180/typeerror-image-data-can-not-convert-to-float">TypeError: Image data can not convert to float</a>, <a href="https://stackoverflow.com/questions/37800833/typeerror-image-data-can-not-convert-to-float-using-matplotlib">TypeError: Image data can not convert to float using matplotlib</a>, <a href="https://stackoverflow.com/questions/35822730/type-error-image-data-can-not-convert-to-float">Type Error: Image data can not convert to float</a>) but i don't see any solution there that helps me.</p>
  
  <p>I'm trying to populate a numpy-array with floating point data and the plot it using imshow. The data in the Y-direction (almost) a Hermite polynomial and a Gaussian envelope, whereas the X-direction is just a Gaussian envelope.</p>
  
  <pre><code>from __future__ import print_function
  import numpy as np
  import matplotlib.pyplot as plt
  
  ####First we set Ne
  Ne=25
  
  ###Set up a mesh with size sqrt(Ne) X sqrt(Ne)
  sqrtNe=int(np.sqrt(Ne))
  Ky=np.array(range(-sqrtNe,sqrtNe+1),dtype=float)
  Kx=np.array(range(-sqrtNe,sqrtNe+1),dtype=float)
  [KXmesh,KYmesh]=np.meshgrid(Kx,Ky,indexing='ij')
  
  ##X-direction is gussian envelope
  AxMesh=np.exp(-(np.pi*KXmesh**2)/(4.0*Ne))
  
  Nerror=21 ###This is where the error shows up
  for n in range(Nerror,Ne):
      ##Y-direction is a polynomial of degree n ....
      AyMesh=0.0
      for i in range(n/2+1):
          AyMesh+=(-1)**i*(np.sqrt(2*np.pi)*2*KYmesh)**(n-2*i)/(np.math.factorial(n-2*i)*np.math.factorial(i))
      ### .... times a gaussian envelope
      AyMesh=AyMesh*np.exp(-np.pi*KYmesh**2)
      AyMesh=AyMesh/np.max(np.abs(AyMesh))
      WeightMesh=AyMesh*AxMesh
      print("n:",n)
      plt.figure()
      ####Error occurs here #####
      plt.imshow(WeightMesh,interpolation='nearest')
      plt.show(block=False)
  </code></pre>
  
  <p>When the code reaches the impow then i get the following error message</p>
  
  <pre><code>Traceback (most recent call last):
    File "FDOccupation_mimimal.py", line 30, in &lt;module&gt;
      plt.imshow(WeightMesh,interpolation='nearest')
    File "/usr/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 3022, in imshow
      **kwargs)
    File "/usr/lib/python2.7/dist-packages/matplotlib/__init__.py", line 1814, in inner
      return func(ax, *args, **kwargs)
    File "/usr/lib/python2.7/dist-packages/matplotlib/axes/_axes.py", line 4947, in imshow
      im.set_data(X)
    File "/usr/lib/python2.7/dist-packages/matplotlib/image.py", line 449, in set_data
      raise TypeError("Image data can not convert to float")
  TypeError: Image data can not convert to float
  </code></pre>
  
  <p>If i replace the code </p>
  
  <pre><code>AyMesh=0.0
  for i in range(n/2+1):
      AyMesh+=(-1)**i*(np.sqrt(2*np.pi)*2*KYmesh)**(n-2*i)/(np.math.factorial(n-2*i)*np.math.factorial(i))
  ### .... times a gaussian envelope
  AyMesh=AyMesh*np.exp(-np.pi*KYmesh**2)
  AyMesh=AyMesh/np.max(np.abs(AyMesh))
  </code></pre>
  
  <p>with simply </p>
  
  <pre><code>AyMesh=KYmesh**n*np.exp(-np.pi*KYmesh**2)
  AyMesh=AyMesh/np.max(np.abs(AyMesh))
  </code></pre>
  
  <p>the problem goes away!?
  Does anyone understand what is happening here?</p>