import matplotlib.pyplot as plt
t, d, dy = np.loadtxt("MotionData.txt",
      skiprows=1 , unpack=True)

  • loadtxt is a numpy function. In order to use it you must import numpy before calling np.loadtxt(filename)
  • Lets break the line t, d, dy = np.loadtxt("MotionData.txt", skiprows=1 , unpack=True) one component at a time.

    --> loadtxt reads the columns of data in the text file MotionData.txt to the array names listed to the left of the equal sign. In this case it is t , d, dy
    --> loadtxt function takes three arguments. --> loadtxt function can recognize space as a column separator.

  • The first argument "MotionData.txt"is the name of the file you are reading. In this case it is referred to as "MotionData.txt".
  • The second argument skiprows=1 is the number of rows you want to skip before reading your file. Sometimes your file contains a header and you need to skip a few lines. In this case you are skipping the columns names only which is one line so we feed skiprows the value of 1.
  • The third argument is unpack=Truetelling loadtxt to "unpack" or output data directly into arrays.
    Note that the only needed input for loadtxt to read a file is the filename. However, in this particular example. We needed both provided options to unpack data and read to array and to skip the header.