def drawDF(df, x, columns, colors=None, axes=None):
    from collections import Counter
    if axes is not None:
        num_axes = Counter(axes)
        nrows = max(num_axes.values())
        ncols = len(num_axes.keys())
    X = df[x]
    ax1 = None
    if colors is None: colors = color_grad(len(columns))
    for i, k in enumerate(columns):
        if axes is None:
            plt.plot(X, df[k], label=k, color=colors[i])
        else:
            ax = plt.subplot(nrows,
                             ncols,
                             ncols * (i % nrows) + axes[i],
                             sharex=ax1)
            ax.plot(X, df[k], label=k, color=colors[i])
            plt.ylabel(k)
            if ax1 is None: ax1 = ax
        plt.minorticks_on()
        plt.grid(b=False, which='major', axis='x', color='b', linestyle='-')
        plt.grid(b=False,
                 which='minor',
                 axis='x',
                 color='0.15',
                 linestyle='--')
        plt.grid(b=False, which='major', axis='y', color='b', linestyle='-')
        #     plt.legend(bbox_to_anchor=(1.01, 1), loc=2, borderaxespad=0.0)
    plt_show_maxed()
Пример #2
0
def sim_PointNav():
    P = 2
    D = 0.1
    AAk = 0.5
    pid = PID(P, 0, D, 0, 10)
    accel = np.arange(0.1, 1.1, 0.1)
    distance = 500
    distanceF = 0.1
    cols = color_grad(len(accel))
    for i, a in enumerate(accel):
        d = [distance]
        v = [0]
        act = [0]
        t = 0
        A = [0]
        while d[-1] > 0:
            pid.kp = P * a / clampL(v[-1], 0.01)
            act.append(pid.update(d[-1] * distanceF))
            aa = a * AAk

            if v[-1] < pid.action:
                if A[-1] < a: A.append(A[-1] + a * AAk * dt)
                else: A.append(a)
            elif v[-1] > pid.action:
                if A[-1] > -a: A.append(A[-1] - a * AAk * dt)
                else: A.append(-a)
            elif A[-1] > 0: A.append(A[-1] - a * AAk * dt)
            elif A[-1] < 0: A.append(A[-1] + a * AAk * dt)
            else: A.append(0)
            #             print 'd=% 8.4f, v=% 8.4f, act=% 8.4f, A=% 8.4f' % (d[-1], v[-1], act[-1], A[-1])
            v.append(v[-1] + A[-1] * dt)
            d.append(d[-1] - v[-1] * dt)
            t += dt
        print 'accel=%.2f, time: %.1fs' % (a, t)
        print len(d), len(A)
        plt.subplot(3, 1, 1)
        plt.plot(d, v, color=cols[i], label="accel=%.2f" % a)
        plt.ylabel("V")
        plt.xlabel("distance")
        plt.subplot(3, 1, 2)
        plt.plot(d, act, color=cols[i], label="accel=%.2f" % a)
        plt.ylabel("act")
        plt.xlabel("distance")
        plt.subplot(3, 1, 3)
        plt.plot(d, A, color=cols[i], label="accel=%.2f" % a)
        plt.ylabel("real accel");
        plt.xlabel("distance")
    plt.legend()
    plt_show_maxed()
 def analyze_results(cls, cols, col, *results):
     colors = color_grad(len(results))
     for i, result in enumerate(results):
         name, time, error, action, thrust, zero_stats = result
         if zero_stats:
             print '\n%s\n' % str(zero_stats)
         print '=' * 80
         ax = plt.subplot(3, cols, col)
         plt.plot(time, error, label=name, color=colors[i])
         plt.ylabel('error (deg)')
         plt.legend()
         plt.subplot(3, cols, cols+col, sharex=ax)
         plt.plot(time, action, color=colors[i])
         plt.ylabel('action')
         plt.subplot(3, cols, cols*2+col, sharex=ax)
         plt.plot(time, thrust, color=colors[i])
         plt.xlabel('time')
         plt.ylabel('thrust')
Пример #4
0
 def analyze_results(cls, cols, col, *results):
     colors = color_grad(len(results))
     for i, result in enumerate(results):
         name, time, error, action, thrust, zero_stats = result
         if zero_stats:
             print '\n%s\n' % str(zero_stats)
         print '=' * 80
         ax = plt.subplot(3, cols, col)
         plt.plot(time, error, label=name, color=colors[i])
         plt.ylabel('error (deg)')
         plt.legend()
         plt.subplot(3, cols, cols + col, sharex=ax)
         plt.plot(time, action, color=colors[i])
         plt.ylabel('action')
         plt.subplot(3, cols, cols * 2 + col, sharex=ax)
         plt.plot(time, thrust, color=colors[i])
         plt.xlabel('time')
         plt.ylabel('thrust')
Пример #5
0
def draw_vectors(*vecs):
    if not vecs: return;
    X, Y, Z, U, V, W = zip(*(xzy(v) + xzy(v) for v in vecs))
    colors = color_grad(len(vecs), 3)
    fig = plt.figure()
    ax = fig.gca(projection='3d')
    ax.quiver(X, Y, Z, U, V, W, colors=colors, lw=2, arrow_length_ratio=0.1)
    ax.set_xlim([-1, 1])
    ax.set_ylim([-1, 1])
    ax.set_zlim([-1, 1])
    ax.set_xlabel('r')
    ax.set_ylabel('f')
    ax.set_zlabel('u')
    legends = []
    for i in range(len(vecs)):
        legends.append(mlines.Line2D([], [], color=colors[i * 3], label=str(i + 1)))
    plt.legend(handles=legends)
    plt.show()
def drawDF(df, x, columns, colors=None, axes=None):
    from collections import Counter
    if axes is not None:
        num_axes = Counter(axes)
        nrows = max(num_axes.values())
        ncols = len(num_axes.keys())
    X = df[x]
    ax1 = None
    if colors is None: colors = color_grad(len(columns))
    for i, k in enumerate(columns):
        if axes is None:
            plt.plot(X, df[k], label=k, color=colors[i])
        else:
            ax = plt.subplot(nrows, ncols, ncols * (i % nrows) + axes[i], sharex=ax1)
            ax.plot(X, df[k], label=k, color=colors[i])
            plt.ylabel(k)
            if ax1 is None: ax1 = ax
        plt.minorticks_on()
        plt.grid(b=False, which='major', axis='x', color='b', linestyle='-')
        plt.grid(b=False, which='minor', axis='x', color='0.15', linestyle='--')
        plt.grid(b=False, which='major', axis='y', color='b', linestyle='-')
        #     plt.legend(bbox_to_anchor=(1.01, 1), loc=2, borderaxespad=0.0)
    plt_show_maxed()
 def analyze_results(cls, cols, col, *results):
     colors = color_grad(len(results) + 1)
     gcolor = colors[-1]
     for i, result in enumerate(results):
         name, time, error, action, addons, zero_stats = result
         if zero_stats:
             print '\n%s\n' % str(zero_stats)
         print '=' * 80
         nplots = 2 + len(addons)
         ax = plt.subplot(nplots, cols, col)
         plt.plot(time, error, label=name, color=colors[i])
         cls._draw_grid(gcolor)
         plt.ylabel('error')
         plt.legend()
         plt.subplot(nplots, cols, cols + col, sharex=ax)
         plt.plot(time, action, color=colors[i])
         cls._draw_grid(gcolor)
         plt.ylabel('action')
         if addons:
             for curve, ylab in addons:
                 plt.plot(time, curve, color=colors[i])
                 cls._draw_grid(gcolor)
                 plt.ylabel(ylab)
         plt.xlabel('time')
Пример #8
0
 def analyze_results(cls, cols, col, *results):
     colors = color_grad(len(results)+1)
     gcolor = colors[-1]
     for i, result in enumerate(results):
         name, time, error, action, addons, zero_stats = result
         if zero_stats:
             print('\n%s\n' % str(zero_stats))
         print('=' * 80)
         nplots = 2+len(addons)
         ax = plt.subplot(nplots, cols, col)
         plt.plot(time, error, label=name, color=colors[i])
         cls._draw_grid(gcolor)
         plt.ylabel('error')
         plt.legend()
         plt.subplot(nplots, cols, cols+col, sharex=ax)
         plt.plot(time, action, color=colors[i])
         cls._draw_grid(gcolor)
         plt.ylabel('action')
         if addons:
             for curve, ylab in addons:
                 plt.plot(time, curve, color=colors[i])
                 cls._draw_grid(gcolor)
                 plt.ylabel(ylab)
         plt.xlabel('time')