title: Plotting 3D trajectory from CSV data using matplotlib
body: <p>I'm trying to plot a 3D trajectory of a vehicle that comes from a CSV file, plotting is easy, I want to make the animation, actually a "replay" of the movements. I based my code from this example (<a href="http://matplotlib.org/examples/animation/simple_3danim.html" rel="nofollow">http://matplotlib.org/examples/animation/simple_3danim.html</a>) and then just modify it to only plot one line and to read the data from a CSV file being read by pandas, the code looks like this:</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  import mpl_toolkits.mplot3d.axes3d as p3
  import matplotlib.animation as animation
  import pandas as pd
  
  def update_lines(num, data, line):
      # NOTE: there is no .set_data() for 3 dim data...
      x = data['x'].values[num]
      y = data['y'].values[num]
      z = data['z'].values[num]
      line[0].set_data(x,y)
      line[0].set_3d_properties(z)
      print z
      return line
  
  # Attaching 3D axis to the figure
  fig = plt.figure()
  ax = p3.Axes3D(fig)
  
  # Reading the data from a CSV file using pandas
  data = pd.read_csv('data.csv',sep=',',header=0)
  
  # Creating fifty line objects.
  # NOTE: Can't pass empty arrays into 3d version of plot()
  x = np.array([0])
  y = np.array([0])
  z = np.array([0])
  
  line = ax.plot(x, y, z)
  
  # Setting the axes properties
  ax.set_xlim3d([0.0, 3.0])
  ax.set_xlabel('X')
  
  ax.set_ylim3d([0.0, 3.0])
  ax.set_ylabel('Y')
  
  ax.set_zlim3d([0.0, 2.0])
  ax.set_zlabel('Z')
  
  ax.set_title('3D Test')
  
  # Creating the Animation object
  line_ani = animation.FuncAnimation(fig, update_lines, len(data), fargs=(data, line),
                                     interval=10, blit=False)
  
  plt.show()
  </code></pre>
  
  <p>I print the z just to see if the data is being iterated correctly, but all I get is a white plot like this:</p>
  
  <p><a href="http://i.stack.imgur.com/khs7M.png" rel="nofollow">Plot showing absolutely nothing.</a></p>