title: surface plots for rectangular arrays in matplotlib
body: <p>I am trying to use matplotlib to generate surface plot of a rectangular array (in my case, it's 47x70). The way this array is organized is:</p>
  
  <p>47 - this dimension indicates the number of features</p>
  
  <p>70 - this dimension indicates the number of samples</p>
  
  <p>The array contains values for these features across each sample.</p>
  
  <p>If I were to generate a surface plot in MATLAB or Octave, it's really simple.</p>
  
  <p><code>vals = csvread("vals.csv");
  surf(vals)
  </code></p>
  
  <p>The output looks something like this - </p>
  
  <p><img src="https://i.stack.imgur.com/3GaQ6.png" alt="Surface plot of a 47x70 array generated using numpy.random.randint"></p>
  
  <p>The array in vals.csv was generated as follows - </p>
  
  <pre><code>tempvals = np.random.randint(0, 10000, size = (47, 70))
  np.savetxt("vals.csv", tempvals, delimiter=',')
  </code></pre>
  
  <p>How can I do this in python/matplotlib?</p>
  
  <p><a href="https://stackoverflow.com/questions/11766536/matplotlib-3d-surface-from-a-rectangular-array-of-heights">There is a pretty nice answer here</a>. However, this answer uses some interpolation which I cannot use. I want to plot my values directly.</p>
  
  <p>I tried writing something very basic. Like this - </p>
  
  <pre><code>import numpy as np
  from mpl_toolkits.mplot3d import Axes3D
  import matplotlib.pyplot as plt
  
  vals = np.genfromtxt('vals.csv', delimiter=',')
  
  fig1 = plt.figure(1, figsize = (9, 6))
  ax1 = fig1.add_subplot(111, projection = '3d')
  xax = np.arange(0, 46)
  yax = np.arange(0, 70)
  xax, yax = np.meshgrid(yax, xax)
  
  Axes3D.plot3D(xax, yax, vals)
  </code></pre>
  
  <p>This, of course, fails with the error - </p>
  
  <p><code>AttributeError: 'numpy.ndarray' object has no attribute 'has_data'</code></p>
  
  <p>I have gone through <a href="https://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#wireframe-plots" rel="nofollow noreferrer">this entire page</a> but I am missing something. How can I generate surface plots for rectangular arrays?</p>