Example #1
0
  def plot(self, cart, units='m'):
    '''
    Purpose:
      plot the trajectory and velocity for the data and model given.
    '''
    x, y, v, yErr, vErr = self.calc_error(cart)
        
    fig = plt.figure(figsize=(14,10))
    ax = fig.add_subplot(211)
    
    if units != 'm':
      x = func.m_to_yards(x)
      y = func.m_to_inches(y)
      v = func.m_to_ft(v)
      traj_x = func.m_to_yards(traj_x)
      traj   = func.m_to_inches(traj)
      xunit = 'yards'
      yunit = 'inches'
      vunit = 'feet/s'
    else:
      xunit = 'm'
      yunit = 'm'
      vunit = 'm/s'

    if len(cart.traj) > 1:
      plt.plot(cart.traj_x, 
               cart.traj, 'r.', label='Data')
    plt.plot(x, y, label=self.intMethod, lw=2)
    plt.text(min(x) + 10, min(y) + (max(y) - min(y))/10.0, 
             'Mean-Squared Err: %f m' % yErr)
    plt.text(min(x) + 10, min(y) + (max(y) - min(y))/100.0, 
             'Muzzle Velocity: %.0f m/s' % cart.mv)
    leg = plt.legend(loc='lower left')
    leg.get_frame().set_alpha(0.5)
    plt.xlabel('Distance (%s)' % xunit)
    plt.ylabel('Drop (%s)' % yunit)
    plt.title('Trajectory for ' + cart.name)
    plt.grid()
    
    ax = fig.add_subplot(212)
    
    if cart.vel != None:
      plt.plot(cart.vel_x, 
               cart.vel, 'r.', label='Data')
      plt.text(min(x)+10, min(v)+10 , 'Mean-Squared Err: %f m/s' % (vErr))
    
    plt.plot(x, v, label=self.intMethod, lw=2)
    plt.xlabel('Distance (%s)' % xunit)
    plt.ylabel('Velocity (%s)' % vunit)
    plt.title('Velocity for ' + cart.name)
    plt.grid()
    
    plt.show()
Example #2
0
 def plot_all(self, units='m'):
   '''
   Purpose:
     plot the trajectory and velocity for the data and model given.
   '''
   fig = plt.figure(figsize=(12,6))
   ax1 = fig.add_subplot(211)
   ax2 = fig.add_subplot(212)
   
   for i in range(self.n):
     x, y, v, yErr, vErr = self.calc_error(self.cart[i])
   
     if units != 'm':
       x = func.m_to_yards(x)
       y = func.m_to_inches(y)
       v = func.m_to_ft(v)
       traj_x = func.m_to_yards(self.cart[i].x)
       traj   = func.m_to_inches(self.cart[i].traj)
       xunit = 'yards'
       yunit = 'inches'
       vunit = 'feet/s'
     else:
       xunit = 'm'
       yunit = 'm'
       vunit = 'm/s'
     
     if len(self.cart[i].traj) > 1:
       ax1.plot(traj_x, traj,
                'r.', label='%s Data' % self.cart[i].name)
     ax1.plot(x, y, lw=2, 
              label=self.cart[i].name)
   
     if self.cart[i].vel != None:
       ax2.plot(self.cart[i].vel_x, self.cart[i].vel,
                'r.', label='%s Data' % self.cart[i].name)
     ax2.plot(x, v, lw=2, 
              label=self.cart[i].name)
   
   leg = ax1.legend(loc='lower left')
   leg.get_frame().set_alpha(0.5)
   ax1.set_xlabel('Distance (%s)' % xunit)
   ax1.set_ylabel('Drop (%s)' % yunit)
   ax1.grid()
   leg = ax2.legend()
   leg.get_frame().set_alpha(0.5)
   ax2.set_xlabel('Distance (%s)' % xunit)
   ax2.set_ylabel('Velocity (%s)' % vunit)
   ax2.grid()
   
   plt.show()