title: IndexError: index out of bounds When tryin to plot in Matplotlib
body: <p>I am trying to convert the following code from Trefethen's Spectral Methods in MATLAB to Python. But run into the following error regarding an index out of bounds. I am a bit confused as to what index is out of bounds and how to fix it. Any help would be appreciated.</p>
  
  <p>Error</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Documents and Settings\My Documents\Computational Physics\Wave-eqn.py", line 56, in &lt;module&gt;
  ax.plot_wireframe(x,tdata,data,rstride=10, cstride=10)
    File "C:\Python32\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py", line 906, in  plot_wireframe
      tylines = [tY[i] for i in cii]
    File "C:\Python32\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py", line 906, in  &lt;listcomp&gt;
      tylines = [tY[i] for i in cii]
  IndexError: index out of bounds
  </code></pre>
  
  <p>Trefethen's Code</p>
  
  <pre><code>% p6.m - variable coefficient wave equation using differentiation matrices
  
  % Grid, variable coefficient, and initial data:
  N = 512; h = 2*pi/N; x = h*(1:N); t = 0; dt = h/4;
  a = .1;
  c = a + sin (x-1).^2;
  v = exp(-100*(x-1).^2); vold = exp(-100*(x-a*dt-1).^2);
  
  column = [0 .5*(-1).^(1:N-1).*cot((1:N-1)*h/2)];
  D = toeplitz(column,-column);
  
  % Time-stepping by leap frog formula:
  tmax = 15; tplot = .15; clf, drawnow, set(gcf,'renderer','zbuffer')
  plotgap = round(tplot/dt); dt = tplot/plotgap;
  nplots = round(tmax/tplot);
  data = [v; zeros(nplots,N)]; tdata = t;
  for i = 1:nplots
   for n = 1:plotgap
          t = t+dt;
          %       v_hat = fft(v);
          %       w_hat = 1i*[0:N/2-1 0 -N/2+1:-1] .* v_hat;
          %       w = real(ifft(w_hat));
          w = (D*v')';
          vnew = vold - 2*dt*c.*w; vold = v; v = vnew;
      end
      data(i+1,:) = v; tdata = [tdata; t];
  end
  waterfall(x,tdata,data), view(10,70), colormap(1e-6*[1 1 1]);
  axis([0 2*pi 0 tmax 0 3]), ylabel t, zlabel u, grid off
  </code></pre>
  
  <p>My Code </p>
  
  <pre><code>import numpy as np
  from numpy import *
  from math import  pi
  from scipy.linalg import toeplitz
  from scipy.special import cotdg
  from mpl_toolkits.mplot3d import axes3d
  import matplotlib.pyplot as plt
  
  
  N = 512
  h = (2*np.pi)/N
  x = h*(np.arange(N)+1)
  t = 0
  dt = h/4.
  a = .1
  c = a + np.sin(x - 1)**2
  v = np.exp(-100 * (x - 1)**2)
  vold = np.exp(-100 * (x - a*dt - 1)**2)
  
  column = ((0.5*(-1)**arange(N))*cotdg(arange(N))*(h/2));
  D = toeplitz(column,-column);
  #print(D.shape);
  
  
  tmax = 15   
  tplot = .15
  plotgap = int(around(tplot/dt));print(plotgap)
  dt = tplot/plotgap
  nplots = int(round((tmax/tplot)));print(nplots)
  k = np.zeros(((nplots,N))) 
  data = np.concatenate((v.reshape((512,1)).transpose(), k))
  tdata = t
  
  for i in range(nplots):
      for n in range(plotgap):
          t = t+dt
          w = (D*v)
          vnew = vold-2*dt*c*w
          vold = v
          v = vnew
      data[i,:] = v[0,:]
      tdata = vstack([tdata, t])
  print('shape data =',data.shape)
  print('shape v =',v.shape)
  print('shape tdata =',tdata.shape)
  print('shape x =',x.shape)
  
  fig = plt.figure()
  ax = fig.add_subplot(111, projection='3d')
  ax.plot_wireframe(x,tdata,data,rstride=10, cstride=10)
  plt.show()
  </code></pre>
  
  <p>Shapes of arrays done by python </p>
  
  <pre><code> shape data = (101, 512)
   shape tdata = (101, 1)
   shape x = (512,)
  </code></pre>
  
  <p>I had a friend run the size() command in MatLab for this code and he came up with these shapes for the arrays </p>
  
  <pre><code>data =  101 512
  tdata = 101 1
  x =     1   512
  </code></pre>