python类subplot()的实例源码

lms.py 文件源码 项目:Spherical-robot 作者: Evan-Zhao 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def plot(l, x1, x2, y, e):
    # Plot
    time_range = numpy.arange(0, l)
    pl.figure(1)
    pl.subplot(221)
    pl.plot(time_range, x1)
    pl.title("Input signal")
    pl.subplot(222)
    pl.plot(time_range, x2, c="r")
    pl.plot(time_range, y, c="b")
    pl.title("Reference signal")
    pl.subplot(223)
    pl.plot(time_range, e, c="r")
    pl.title("Noise")
    pl.xlabel("time")
    pl.show()
test_msckf.py 文件源码 项目:prototype 作者: chutsu 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_augment_state(self):
        self.msckf.augment_state()

        N = self.msckf.N()
        self.assertTrue(self.msckf.P_cam is not None)
        self.assertTrue(self.msckf.P_imu_cam is not None)
        self.assertEqual(self.msckf.P_cam.shape, (N * 6, N * 6))
        self.assertEqual(self.msckf.P_imu_cam.shape, (15, N * 6))
        self.assertEqual(self.msckf.N(), 2)

        self.assertTrue(np.array_equal(self.msckf.cam_states[0].q_CG,
                                       self.msckf.ext_q_CI))
        self.assertEqual(self.msckf.counter_frame_id, 2)

        # Plot matrix
        # debug = True
        debug = False
        if debug:
            ax = plt.subplot(111)
            ax.matshow(self.msckf.P())
            plt.show()
test_imu_state.py 文件源码 项目:prototype 作者: chutsu 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_F(self):
        w_hat = np.array([1.0, 2.0, 3.0])
        q_hat = np.array([0.0, 0.0, 0.0, 1.0])
        a_hat = np.array([1.0, 2.0, 3.0])
        w_G = np.array([0.1, 0.1, 0.1])

        F = self.imu_state.F(w_hat, q_hat, a_hat, w_G)

        # -- First row --
        self.assertTrue(np_equal(F[0:3, 0:3], -skew(w_hat)))
        self.assertTrue(np_equal(F[0:3, 3:6], -np.ones((3, 3))))
        # -- Third Row --
        self.assertTrue(np_equal(F[6:9, 0:3], dot(-C(q_hat).T, skew(a_hat))))
        self.assertTrue(np_equal(F[6:9, 6:9], -2.0 * skew(w_G)))
        self.assertTrue(np_equal(F[6:9, 9:12], -C(q_hat).T))
        self.assertTrue(np_equal(F[6:9, 12:15], -skewsq(w_G)))
        # -- Fifth Row --
        self.assertTrue(np_equal(F[12:15, 6:9], np.ones((3, 3))))

        # Plot matrix
        if self.debug:
            ax = plt.subplot(111)
            ax.matshow(F)
            plt.show()
test_imu_state.py 文件源码 项目:prototype 作者: chutsu 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_G(self):
        q_hat = np.array([0.0, 0.0, 0.0, 1.0]).reshape((4, 1))
        G = self.imu_state.G(q_hat)

        # -- First row --
        self.assertTrue(np_equal(G[0:3, 0:3], -np.ones((3, 3))))
        # -- Second row --
        self.assertTrue(np_equal(G[3:6, 3:6], np.ones((3, 3))))
        # -- Third row --
        self.assertTrue(np_equal(G[6:9, 6:9], -C(q_hat).T))
        # -- Fourth row --
        self.assertTrue(np_equal(G[9:12, 9:12], np.ones((3, 3))))

        # Plot matrix
        if self.debug:
            ax = plt.subplot(111)
            ax.matshow(G)
            plt.show()
test_imu_state.py 文件源码 项目:prototype 作者: chutsu 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_J(self):
        # Setup
        cam_q_CI = np.array([0.0, 0.0, 0.0, 1.0])
        cam_p_IC = np.array([1.0, 1.0, 1.0])
        q_hat_IG = np.array([0.0, 0.0, 0.0, 1.0])
        N = 1
        J = self.imu_state.J(cam_q_CI, cam_p_IC, q_hat_IG, N)

        # Assert
        C_CI = C(cam_q_CI)
        C_IG = C(q_hat_IG)
        # -- First row --
        self.assertTrue(np_equal(J[0:3, 0:3], C_CI))
        # -- Second row --
        self.assertTrue(np_equal(J[3:6, 0:3], skew(dot(C_IG.T, cam_p_IC))))
        # -- Third row --
        self.assertTrue(np_equal(J[3:6, 12:15], I(3)))

        # Plot matrix
        if self.debug:
            ax = plt.subplot(111)
            ax.matshow(J)
            plt.show()
models_learners.py 文件源码 项目:smp_base 作者: x75 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def visualize_model_init(self):
        """smpSHL.visualize_model_init

        Init model visualization
        """

        self.Ridx  = np.random.choice(self.modelsize, min(30, int(self.modelsize * 0.1)))
        self.Rhist = []
        self.losshist = []
        self.Whist = []

        fig = make_figure()
        # print "fig", fig
        self.figs.append(fig)
        gs = make_gridspec(5, 1)
        for subplot in gs:
            self.figs[0].add_subplot(subplot)
mean_plotter.py 文件源码 项目:gps 作者: cbfinn 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, fig, gs, label='mean', color='black', alpha=1.0, min_itr=10):
        self._fig = fig
        self._gs = gridspec.GridSpecFromSubplotSpec(1, 1, subplot_spec=gs)
        self._ax = plt.subplot(self._gs[0])

        self._label = label
        self._color = color
        self._alpha = alpha
        self._min_itr = min_itr

        self._ts = np.empty((1, 0))
        self._data_mean = np.empty((1, 0))
        self._plots_mean = self._ax.plot([], [], '-x', markeredgewidth=1.0,
                color=self._color, alpha=1.0, label=self._label)[0]

        self._ax.set_xlim(0-0.5, self._min_itr+0.5)
        self._ax.set_ylim(0, 1)
        self._ax.minorticks_on()
        self._ax.legend(loc='upper right', bbox_to_anchor=(1, 1))

        self._init = False

        self._fig.canvas.draw()
        self._fig.canvas.flush_events()   # Fixes bug with Qt4Agg backend
plot.py 文件源码 项目:DeepMonster 作者: olimastro 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def show_samples(y, ndim, nb=10, cmap=''):
    if ndim == 4:
        for i in range(nb**2):
            plt.subplot(nb, nb, i+1)
            plt.imshow(y[i], cmap=cmap, interpolation='none')
            plt.axis('off')

    else:
        x = y[0]
        y = y[1]
        plt.figure(0)
        for i in range(10):
            plt.subplot(2, 5, i+1)
            plt.imshow(x[i], cmap=cmap, interpolation='none')
            plt.axis('off')

        plt.figure(1)
        for i in range(10):
            plt.subplot(2, 5, i+1)
            plt.imshow(y[i], cmap=cmap, interpolation='none')
            plt.axis('off')

    plt.show()
mean_plotter.py 文件源码 项目:gps_superball_public 作者: young-geng 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self, fig, gs, label='mean', color='black', alpha=1.0, min_itr=10):
        self._fig = fig
        self._gs = gridspec.GridSpecFromSubplotSpec(1, 1, subplot_spec=gs)
        self._ax = plt.subplot(self._gs[0])

        self._label = label
        self._color = color
        self._alpha = alpha
        self._min_itr = min_itr

        self._ts = np.empty((1, 0))
        self._data_mean = np.empty((1, 0))
        self._plots_mean = self._ax.plot([], [], '-x', markeredgewidth=1.0,
                color=self._color, alpha=1.0, label=self._label)[0]

        self._ax.set_xlim(0-0.5, self._min_itr+0.5)
        self._ax.set_ylim(0, 1)
        self._ax.minorticks_on()
        self._ax.legend(loc='upper right', bbox_to_anchor=(1, 1))

        self._init = False

        self._fig.canvas.draw()
        self._fig.canvas.flush_events()   # Fixes bug with Qt4Agg backend
AdmixAsteriskK8.py 文件源码 项目:bnpy 作者: bnpy 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def showExampleDocs(pylab=None, nrows=3, ncols=3):
    if pylab is None:
        from matplotlib import pylab
    Data = get_data(seed=0, nObsPerDoc=200)
    PRNG = np.random.RandomState(0)
    chosenDocs = PRNG.choice(Data.nDoc, nrows * ncols, replace=False)
    for ii, d in enumerate(chosenDocs):
        start = Data.doc_range[d]
        stop = Data.doc_range[d + 1]
        Xd = Data.X[start:stop]
        pylab.subplot(nrows, ncols, ii + 1)
        pylab.plot(Xd[:, 0], Xd[:, 1], 'k.')
        pylab.axis('image')
        pylab.xlim([-1.5, 1.5])
        pylab.ylim([-1.5, 1.5])
        pylab.xticks([])
        pylab.yticks([])
    pylab.tight_layout()
# Set Toy Parameters
###########################################################
plot.py 文件源码 项目:sr 作者: chutsu 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def plot_tree_data(data, indicies_x, indicies_y, model):
    plt.subplot(3, 1, 1)
    data, indicies_x, indicies_y, model = load_tree_data()
    data_line, = plt.plot(data, color="blue", label="data")
    data_indicies_line, = plt.plot(
        indicies_x,
        indicies_y,
        "o",
        color="green",
        label="fitness predictors"
    )
    model_line, = plt.plot(model, color="red", label="model")
    plt.title("Data and Model Output")
    plt.legend()

    return data_line, data_indicies_line, model_line
make_plots.py 文件源码 项目:sr 作者: chutsu 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def plot_tree_data(data, indicies_x, indicies_y, model, plot_indicies=False):
    plt.subplot(3, 1, 1)
    plt.plot(data, "o", color="blue", label="data")
    plt.plot(model, color="red", label="model")
    plt.ylim([-10, 10])

    if plot_indicies:
        plt.plot(
            indicies_x,
            indicies_y,
            "o",
            color="green",
            label="fitness predictors"
        )

    plt.title("Data and Model Output")
    plt.legend()
plot.py 文件源码 项目:POT 作者: rflamary 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def plot1D_mat(a, b, M, title=''):
    """ Plot matrix M  with the source and target 1D distribution

    Creates a subplot with the source distribution a on the left and
    target distribution b on the tot. The matrix M is shown in between.


    Parameters
    ----------
    a : np.array, shape (na,)
        Source distribution
    b : np.array, shape (nb,)
        Target distribution
    M : np.array, shape (na,nb)
        Matrix to plot
    """
    na, nb = M.shape

    gs = gridspec.GridSpec(3, 3)

    xa = np.arange(na)
    xb = np.arange(nb)

    ax1 = pl.subplot(gs[0, 1:])
    pl.plot(xb, b, 'r', label='Target distribution')
    pl.yticks(())
    pl.title(title)

    ax2 = pl.subplot(gs[1:, 0])
    pl.plot(a, xa, 'b', label='Source distribution')
    pl.gca().invert_xaxis()
    pl.gca().invert_yaxis()
    pl.xticks(())

    pl.subplot(gs[1:, 1:], sharex=ax1, sharey=ax2)
    pl.imshow(M, interpolation='nearest')
    pl.axis('off')

    pl.xlim((0, nb))
    pl.tight_layout()
    pl.subplots_adjust(wspace=0., hspace=0.2)
rasta_plp_extractor.py 文件源码 项目:speech_feature_extractor 作者: ZhihaoDU 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def rasta_plp_extractor(x, sr, plp_order=0, do_rasta=True):
    spec = log_power_spectrum_extractor(x, int(sr*0.02), int(sr*0.01), 'hamming', False)
    bark_filters = int(np.ceil(freq2bark(sr//2)))
    wts = get_fft_bark_mat(sr, int(sr*0.02), bark_filters)
    '''
    plt.figure()
    plt.subplot(211)
    plt.imshow(wts)
    plt.subplot(212)
    plt.hold(True)
    for i in range(18):
        plt.plot(wts[i, :])
    plt.show()
    '''
    bark_spec = np.matmul(wts, spec)
    if do_rasta:
        bark_spec = np.where(bark_spec == 0.0, np.finfo(float).eps, bark_spec)
        log_bark_spec = np.log(bark_spec)
        rasta_log_bark_spec = rasta_filt(log_bark_spec)
        bark_spec = np.exp(rasta_log_bark_spec)
    post_spec = postaud(bark_spec, sr/2.)
    if plp_order > 0:
        lpcas = do_lpc(post_spec, plp_order)
        # lpcas = do_lpc(spec, plp_order) # just for test
    else:
        lpcas = post_spec
    return lpcas
gcd.py 文件源码 项目:Spherical-robot 作者: Evan-Zhao 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def plot(l, samp, w1, w2, cor):
    time_range = numpy.arange(0, l) * (1.0 / samp)

    pl.figure(1)
    pl.subplot(211)
    pl.plot(time_range, w1)
    pl.subplot(212)
    pl.plot(time_range, w2, c="r")
    pl.xlabel("time")

    pl.figure(2)
    pl.plot(time_range, cor)
    pl.show()
cut_chan.py 文件源码 项目:Spherical-robot 作者: Evan-Zhao 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def main():
    sampling, maxvalue, wave_data = record.record()

    # Pick out two channels for our study.
    w1, w2 = wave_data[1:3]
    nframes = w1.shape[0]

    # Cut one channel in the tail, while the other in the head,
    # to guarantee same length and first delays second.
    cut_time_len = 0.2  # second
    cut_len = int(cut_time_len * sampling)
    wp1 = w1[:-cut_len]
    wp2 = w2[cut_len:]

    # Get their reduced (amplitude) version, and
    # calculate correlation.
    a = numpy.array(wp1, dtype=numpy.double) / maxvalue
    b = numpy.array(wp2, dtype=numpy.double) / maxvalue
    delay_time = delay.fst_delay_snd(a, b, sampling)

    # Plot the channels, also the correlation.
    time_range = numpy.arange(0, nframes - cut_len)*(1.0/sampling)

    # Still shows the original signal
    pl.figure(1)
    pl.subplot(211)
    pl.plot(time_range, wp1)
    pl.subplot(212)
    pl.plot(time_range, wp2, c="r")
    pl.xlabel("time")
    pl.show()

    # Print delay
    print("Chan 1 delay chan 2 by {0}".format(delay_time))
pad_chan.py 文件源码 项目:Spherical-robot 作者: Evan-Zhao 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def main():
    sampling, maxvalue, wave_data = record.record()

    # Pick out two channels for our study.
    w1, w2 = wave_data[0:2]
    nframes = w1.shape[0]

    # Pad one channel in the head, while the other in the tail,
    # to guarantee same length.
    pad_time_len = 0.01  # second
    pad_len = int(pad_time_len * sampling)
    pad_arr = numpy.zeros(pad_len)
    wp1 = numpy.concatenate((pad_arr, w1))
    wp2 = numpy.concatenate((w2, pad_arr))

    # Get their reduced (amplitude) version, and
    # calculate correlation.
    a = numpy.array(wp1, dtype=numpy.double) / maxvalue
    b = numpy.array(wp2, dtype=numpy.double) / maxvalue
    delay_time = delay.fst_delay_snd(a, b, sampling)

    # Plot the channels, also the correlation.
    time_range = numpy.arange(0, nframes + pad_len)*(1.0/sampling)

    # Still shows the original signal
    pl.figure(1)
    pl.subplot(211)
    pl.plot(time_range, wp1)
    pl.subplot(212)
    pl.plot(time_range, wp2, c="r")
    pl.xlabel("time")
    pl.show()

    # Print delay
    print("Chan 1 delay chan 2 by {0}".format(delay_time))
time_alignment_plotting_tools.py 文件源码 项目:hand_eye_calibration 作者: ethz-asl 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def plot_angular_velocities(title,
                            angular_velocities,
                            angular_velocities_filtered,
                            block=True):
  fig = plt.figure()

  title_position = 1.05

  fig.suptitle(title, fontsize='24')

  a1 = plt.subplot(1, 2, 1)
  a1.set_title(
      "Angular Velocities Before Filtering \nvx [red], vy [green], vz [blue]",
      y=title_position)
  plt.plot(angular_velocities[:, 0], c='r')
  plt.plot(angular_velocities[:, 1], c='g')
  plt.plot(angular_velocities[:, 2], c='b')

  a2 = plt.subplot(1, 2, 2)
  a2.set_title(
      "Angular Velocities After Filtering \nvx [red], vy [green], vz [blue]", y=title_position)
  plt.plot(angular_velocities_filtered[:, 0], c='r')
  plt.plot(angular_velocities_filtered[:, 1], c='g')
  plt.plot(angular_velocities_filtered[:, 2], c='b')

  plt.subplots_adjust(left=0.025, right=0.975, top=0.8, bottom=0.05)

  if plt.get_backend() == 'TkAgg':
    mng = plt.get_current_fig_manager()
    max_size = mng.window.maxsize()
    max_size = (max_size[0], max_size[1] * 0.45)
    mng.resize(*max_size)
  plt.show(block=block)
plots.py 文件源码 项目:nmmn 作者: rsnemmen 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def threehistsx(x1,x2,x3,x1leg='$x_1$',x2leg='$x_2$',x3leg='$x_3$',fig=1,fontsize=12,bins1=10,bins2=10,bins3=10):
    """
Script that pretty-plots three histograms of quantities x1, x2 and x3.

Arguments:
:param x1,x2,x3: arrays with data to be plotted
:param x1leg, x2leg, x3leg: legends for each histogram  
:param fig: which plot window should I use?

Example:
x1=Lbol(AD), x2=Lbol(JD), x3=Lbol(EHF10)

>>> threehists(x1,x2,x3,38,44,'AD','JD','EHF10','$\log L_{\\rm bol}$ (erg s$^{-1}$)')

Inspired by http://www.scipy.org/Cookbook/Matplotlib/Multiple_Subplots_with_One_Axis_Label.
    """
    pylab.rcParams.update({'font.size': fontsize})
    pylab.figure(fig)
    pylab.clf()

    pylab.subplot(3,1,1)
    pylab.hist(x1,label=x1leg,color='b',bins=bins1)
    pylab.legend(loc='best',frameon=False)

    pylab.subplot(3,1,2)
    pylab.hist(x2,label=x2leg,color='r',bins=bins2)
    pylab.legend(loc='best',frameon=False)

    pylab.subplot(3,1,3)
    pylab.hist(x3,label=x3leg,color='y',bins=bins3)
    pylab.legend(loc='best',frameon=False)

    pylab.minorticks_on()
    pylab.subplots_adjust(hspace=0.15)
    pylab.draw()
    pylab.show()
plots.py 文件源码 项目:nmmn 作者: rsnemmen 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def ipyplots():
    """
Makes sure we have exactly the same matplotlib settings as in the IPython terminal 
version. Call this from IPython notebook.

`Source <http://stackoverflow.com/questions/16905028/why-is-matplotlib-plot-produced-from-ipython-notebook-slightly-different-from-te)>`_.
    """
    pylab.rcParams['figure.figsize']=(8.0,6.0)    #(6.0,4.0)
    pylab.rcParams['font.size']=12                #10 
    pylab.rcParams['savefig.dpi']=100             #72 
    pylab.rcParams['figure.subplot.bottom']=.1    #.125
test_msckf.py 文件源码 项目:prototype 作者: chutsu 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def plot_velocity(self, timestamps, vel_true, vel_est):
        N = vel_est.shape[1]
        t = timestamps[:N]
        vel_true = vel_true[:, :N]
        vel_est = vel_est[:, :N]

        # Figure
        plt.figure()
        plt.suptitle("Velocity")

        # X axis
        plt.subplot(311)
        plt.plot(t, vel_true[0, :], color="red", label="Ground_truth")
        plt.plot(t, vel_est[0, :], color="blue", label="Estimate")

        plt.title("x-axis")
        plt.xlabel("Date Time")
        plt.ylabel("ms^-1")
        plt.legend(loc=0)

        # Y axis
        plt.subplot(312)
        plt.plot(t, vel_true[1, :], color="red", label="Ground_truth")
        plt.plot(t, vel_est[1, :], color="blue", label="Estimate")

        plt.title("y-axis")
        plt.xlabel("Date Time")
        plt.ylabel("ms^-1")
        plt.legend(loc=0)

        # Z axis
        plt.subplot(313)
        plt.plot(t, vel_true[2, :], color="red", label="Ground_truth")
        plt.plot(t, vel_est[2, :], color="blue", label="Estimate")

        plt.title("z-axis")
        plt.xlabel("Date Time")
        plt.ylabel("ms^-1")
        plt.legend(loc=0)
test_msckf.py 文件源码 项目:prototype 作者: chutsu 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def plot_attitude(self, timestamps, att_true, att_est):
        # Setup
        N = att_est.shape[1]
        t = timestamps[:N]
        att_true = att_true[:, :N]
        att_est = att_est[:, :N]

        # Figure
        plt.figure()
        plt.suptitle("Attitude")

        # X axis
        plt.subplot(311)
        plt.plot(t, att_true[0, :], color="red", label="Ground_truth")
        plt.plot(t, att_est[0, :], color="blue", label="Estimate")

        plt.title("x-axis")
        plt.legend(loc=0)
        plt.xlabel("Date Time")
        plt.ylabel("rad s^-1")

        # Y axis
        plt.subplot(312)
        plt.plot(t, att_true[1, :], color="red", label="Ground_truth")
        plt.plot(t, att_est[1, :], color="blue", label="Estimate")

        plt.title("y-axis")
        plt.legend(loc=0)
        plt.xlabel("Date Time")
        plt.ylabel("rad s^-1")

        # Z axis
        plt.subplot(313)
        plt.plot(t, att_true[2, :], color="red", label="Ground_truth")
        plt.plot(t, att_est[2, :], color="blue", label="Estimate")

        plt.title("z-axis")
        plt.legend(loc=0)
        plt.xlabel("Date Time")
        plt.ylabel("rad s^-1")
test_msckf.py 文件源码 项目:prototype 作者: chutsu 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_P(self):
        self.assertEqual(self.msckf.P().shape, (21, 21))

        # Plot matrix
        # debug = True
        debug = False
        if debug:
            ax = plt.subplot(111)
            ax.matshow(self.msckf.P())
            plt.show()
test_msckf.py 文件源码 项目:prototype 作者: chutsu 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_H(self):
        # Setup feature track
        track_id = 0
        frame_id = 3
        data0 = KeyPoint(np.array([0.0, 0.0]), 21)
        data1 = KeyPoint(np.array([0.0, 0.0]), 21)
        track = FeatureTrack(track_id, frame_id, data0, data1)

        # Setup track cam states
        self.msckf.augment_state()
        self.msckf.augment_state()
        self.msckf.augment_state()
        self.msckf.augment_state()
        track_cam_states = self.msckf.track_cam_states(track)

        # Feature position
        p_G_f = np.array([[1.0], [2.0], [3.0]])

        # Test
        H_f_j, H_x_j = self.msckf.H(track, track_cam_states, p_G_f)

        # Assert
        self.assertEqual(H_f_j.shape, (4, 3))
        self.assertEqual(H_x_j.shape, (4, 45))

        # Plot matrix
        # debug = True
        debug = False
        if debug:
            ax = plt.subplot(211)
            ax.matshow(H_f_j)
            ax = plt.subplot(212)
            ax.matshow(H_x_j)
            plt.show()
test_imu_state.py 文件源码 项目:prototype 作者: chutsu 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def plot_attitude(self, timestamps, att_true, att_est):
        # Setup
        N = att_est.shape[1]
        t = timestamps[:N]
        att_true = att_true[:, :N]
        att_est = att_est[:, :N]

        # Figure
        plt.figure()
        plt.suptitle("Attitude")

        # X axis
        plt.subplot(311)
        plt.plot(t, att_true[0, :], color="red", label="Ground_truth")
        plt.plot(t, att_est[0, :], color="blue", label="Estimate")

        plt.title("x-axis")
        plt.legend(loc=0)
        plt.xlabel("Date Time")
        plt.ylabel("rad s^-1")

        # Y axis
        plt.subplot(312)
        plt.plot(t, att_true[1, :], color="red", label="Ground_truth")
        plt.plot(t, att_est[1, :], color="blue", label="Estimate")

        plt.title("y-axis")
        plt.legend(loc=0)
        plt.xlabel("Date Time")
        plt.ylabel("rad s^-1")

        # Z axis
        plt.subplot(313)
        plt.plot(t, att_true[2, :], color="red", label="Ground_truth")
        plt.plot(t, att_est[2, :], color="blue", label="Estimate")

        plt.title("z-axis")
        plt.legend(loc=0)
        plt.xlabel("Date Time")
        plt.ylabel("rad s^-1")
test_dataset.py 文件源码 项目:prototype 作者: chutsu 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_step(self):
        # Step
        a_B_history = self.dataset.a_B
        w_B_history = self.dataset.w_B

        for i in range(30):
            (a_B, w_B) = self.dataset.step()
            a_B_history = np.hstack((a_B_history, a_B))
            w_B_history = np.hstack((w_B_history, w_B))

        # Plot
        debug = False
        # debug = True
        if debug:
            plt.subplot(211)
            plt.plot(self.dataset.time_true, a_B_history[0, :], label="ax")
            plt.plot(self.dataset.time_true, a_B_history[1, :], label="ay")
            plt.plot(self.dataset.time_true, a_B_history[2, :], label="az")
            plt.legend(loc=0)

            plt.subplot(212)
            plt.plot(self.dataset.time_true, w_B_history[0, :], label="wx")
            plt.plot(self.dataset.time_true, w_B_history[1, :], label="wy")
            plt.plot(self.dataset.time_true, w_B_history[2, :], label="wz")
            plt.legend(loc=0)
            plt.show()
realtime_plotter.py 文件源码 项目:gps 作者: cbfinn 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, fig, gs, time_window=500, labels=None, alphas=None):
        self._fig = fig
        self._gs = gridspec.GridSpecFromSubplotSpec(1, 1, subplot_spec=gs)
        self._ax = plt.subplot(self._gs[0])

        self._time_window = time_window
        self._labels = labels
        self._alphas = alphas
        self._init = False

        if self._labels:
            self.init(len(self._labels))

        self._fig.canvas.draw()
        self._fig.canvas.flush_events()   # Fixes bug with Qt4Agg backend
plotter_3d.py 文件源码 项目:gps 作者: cbfinn 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self, fig, gs, num_plots, rows=None, cols=None):
        if cols is None:
            cols = int(np.floor(np.sqrt(num_plots)))
        if rows is None:
            rows = int(np.ceil(float(num_plots)/cols))
        assert num_plots <= rows*cols, 'Too many plots to put into gridspec.'

        self._fig = fig
        self._gs = gridspec.GridSpecFromSubplotSpec(8, 1, subplot_spec=gs)
        self._gs_legend = self._gs[0:1, 0]
        self._gs_plot   = self._gs[1:8, 0]

        self._ax_legend = plt.subplot(self._gs_legend)
        self._ax_legend.get_xaxis().set_visible(False)
        self._ax_legend.get_yaxis().set_visible(False)

        self._gs_plots = gridspec.GridSpecFromSubplotSpec(rows, cols, subplot_spec=self._gs_plot)
        self._axarr = [plt.subplot(self._gs_plots[i], projection='3d') for i in range(num_plots)]
        self._lims = [None for i in range(num_plots)]
        self._plots = [[] for i in range(num_plots)]

        for ax in self._axarr:
            ax.tick_params(pad=0)
            ax.locator_params(nbins=5)
            for item in (ax.get_xticklabels() + ax.get_yticklabels() + ax.get_zticklabels()):
                item.set_fontsize(10)

        self._fig.canvas.draw()
        self._fig.canvas.flush_events()   # Fixes bug with Qt4Agg backend
earth_model.py 文件源码 项目:seis_tools 作者: romaguir 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def plot_1d_model(self):
      plt.subplot(131)
      plt.plot(self.rho_bg,self.radius)
      plt.xlabel('density (kg/m3)')
      plt.ylabel('radius (km)')
      plt.subplot(132)
      plt.plot(self.vp_bg,self.radius)
      plt.xlabel('Vp (km/s)')
      plt.ylabel('radius (km)')
      plt.subplot(133)
      plt.plot(self.vs_bg,self.radius)
      plt.xlabel('Vs (km/s)')
      plt.ylabel('radius (km)')
      plt.show()
recurrent_network_2a.py 文件源码 项目:seqrnns 作者: x75 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def gen_data2(k = 0, min_length=50, max_length=55, n_batch=5, freq = 2.):
    print "k", k
    # t = np.linspace(0, 2*np.pi, n_batch)
    t = np.linspace(k*n_batch, (k+1)*n_batch+1, n_batch+1, endpoint=False)
    # print "t.shape", t.shape, t, t[:-1], t[1:]
    # freq = 1.
    Xtmp = np.sin(t[:-1] * freq / (2*np.pi))
    print Xtmp.shape
    # Xtmp = [np.sin(t[i:i+max_length]) for i in range(n_batch)]
    # print len(Xtmp)
    X = np.array(Xtmp).reshape((n_batch, input_size))
    # X = 
    # y = np.zeros((n_batch,))
    y = np.sin(t[1:] * freq / (2 * np.pi)).reshape((n_batch, output_size))
    # print X,y
    # print X.shape, y.shape
    # for i in range(batch_size):
    #     pl.subplot(211)
    #     pl.plot(X[i,:,0])
    #     # pl.subplot(312)
    #     # pl.plot(X[i,:,1])
    # pl.subplot(212)
    # pl.plot(y)
    # pl.show()

    return (X,y)


问题


面经


文章

微信
公众号

扫码关注公众号