python类xlabel()的实例源码

gcd.py 文件源码 项目:Spherical-robot 作者: Evan-Zhao 项目源码 文件源码 阅读 24 收藏 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 项目源码 文件源码 阅读 20 收藏 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 项目源码 文件源码 阅读 19 收藏 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))
visual.py 文件源码 项目:Spherical-robot 作者: Evan-Zhao 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def plot_channel(audio, sampling):
    channels, nframes = audio.shape[0], audio.shape[1]
    time_range = numpy.arange(0, nframes) * (1.0 / sampling)

    for i in range(1, channels + 1):
        pl.figure(i)
        pl.plot(time_range, audio[i - 1])
        pl.xlabel("time{0}".format(i))

    pl.show()
plots.py 文件源码 项目:nmmn 作者: rsnemmen 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def onehist(x,xlabel='',fontsize=12):
    """ 
Script that plots the histogram of x with the corresponding xlabel. 
    """

    pylab.clf()
    pylab.rcParams.update({'font.size': fontsize})
    pylab.hist(x,histtype='stepfilled')
    pylab.legend()
    #### Change the X-axis appropriately ####
    pylab.xlabel(xlabel)
    pylab.ylabel('Number')
    pylab.draw()
    pylab.show()
Top_Trending.py 文件源码 项目:Trending-Places-in-OpenStreetMap 作者: geometalab 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def plot_graphs(df, trending_daily, day_from, day_to, limit, country_code, folder_out=None):
    days = pd.DatetimeIndex(start=day_from, end=day_to, freq='D')
    for day in days:
        fig = plt.figure()
        ax = fig.add_subplot(111)
        plt.rc('lines', linewidth=2)
        data = trending_daily.get_group(str(day.date()))
        places, clusters = top_trending(data, limit)
        for cluster in clusters:
            places.add(max_from_cluster(cluster, data))
        ax.set_prop_cycle(plt.cycler('color', ['r', 'b', 'yellow'] + [plt.cm.Accent(i) for i in np.linspace(0, 1, limit-3)]
                                     ) + plt.cycler('linestyle', ['-', '-', '-', '-', '-', '--', '--', '--', '--', '--']))
        frame = export(places, clusters, data)
        frame.sort_values('trending_rank', ascending=False, inplace=True)
        for i in range(len(frame)):
            item = frame.index[i]
            lat, lon, country = item
            result_items = ReverseGeoCode().get_address_attributes(lat, lon, 10, 'city', 'country_code')
            if 'city' not in result_items.keys():
                mark = "%s (%s)" % (manipulate_display_name(result_items['display_name']),
                                    result_items['country_code'].upper() if 'country_code' in result_items.keys() else country)
            else:
                if check_eng(result_items['city']):
                    mark = "%s (%s)" % (result_items['city'], result_items['country_code'].upper())
                else:
                    mark = "%.2f %.2f (%s)" % (lat, lon, result_items['country_code'].upper())
            gp = df.loc[item].plot(ax=ax, x='date', y='count', label=mark)
        ax.tick_params(axis='both', which='major', labelsize=10)
        ax.set_yscale("log", nonposy='clip')
        plt.xlabel('Date', fontsize='small', verticalalignment='baseline', horizontalalignment='right')
        plt.ylabel('Total number of views (log)', fontsize='small', verticalalignment='center', horizontalalignment='center', labelpad=6)
        gp.legend(loc='best', fontsize='xx-small', ncol=2)
        gp.set_title('Top 10 OSM trending places on ' + str(day.date()), {'fontsize': 'large', 'verticalalignment': 'bottom'})
        plt.tight_layout()
        db = TrendingDb()
        db.update_table_img(plt, str(day.date()), region=country_code)
        plt.close()
dispersion.py 文件源码 项目:Price-Comparator 作者: Thejas-1 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def dispersion_plot(text, words, ignore_case=False, title="Lexical Dispersion Plot"):
    """
    Generate a lexical dispersion plot.

    :param text: The source text
    :type text: list(str) or enum(str)
    :param words: The target words
    :type words: list of str
    :param ignore_case: flag to set if case should be ignored when searching text
    :type ignore_case: bool
    """

    try:
        from matplotlib import pylab
    except ImportError:
        raise ValueError('The plot function requires matplotlib to be installed.'
                     'See http://matplotlib.org/')

    text = list(text)
    words.reverse()

    if ignore_case:
        words_to_comp = list(map(str.lower, words))
        text_to_comp = list(map(str.lower, text))
    else:
        words_to_comp = words
        text_to_comp = text

    points = [(x,y) for x in range(len(text_to_comp))
                    for y in range(len(words_to_comp))
                    if text_to_comp[x] == words_to_comp[y]]
    if points:
        x, y = list(zip(*points))
    else:
        x = y = ()
    pylab.plot(x, y, "b|", scalex=.1)
    pylab.yticks(list(range(len(words))), words, color="b")
    pylab.ylim(-1, len(words))
    pylab.title(title)
    pylab.xlabel("Word Offset")
    pylab.show()
wordfreq_app.py 文件源码 项目:Price-Comparator 作者: Thejas-1 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def plot_word_freq_dist(text):
    fd = text.vocab()

    samples = [item for item, _ in fd.most_common(50)]
    values = [fd[sample] for sample in samples]
    values = [sum(values[:i+1]) * 100.0/fd.N() for i in range(len(values))]
    pylab.title(text.name)
    pylab.xlabel("Samples")
    pylab.ylabel("Cumulative Percentage")
    pylab.plot(values)
    pylab.xticks(range(len(samples)), [str(s) for s in samples], rotation=90)
    pylab.show()
texttiling.py 文件源码 项目:Price-Comparator 作者: Thejas-1 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def demo(text=None):
    from nltk.corpus import brown
    from matplotlib import pylab
    tt = TextTilingTokenizer(demo_mode=True)
    if text is None: text = brown.raw()[:10000]
    s, ss, d, b = tt.tokenize(text)
    pylab.xlabel("Sentence Gap index")
    pylab.ylabel("Gap Scores")
    pylab.plot(range(len(s)), s, label="Gap Scores")
    pylab.plot(range(len(ss)), ss, label="Smoothed Gap scores")
    pylab.plot(range(len(d)), d, label="Depth scores")
    pylab.stem(range(len(b)), b)
    pylab.legend()
    pylab.show()
test_msckf.py 文件源码 项目:prototype 作者: chutsu 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def plot_position(self, pos_true, pos_est, cam_states):
        N = pos_est.shape[1]
        pos_true = pos_true[:, :N]
        pos_est = pos_est[:, :N]

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

        # Ground truth
        plt.plot(pos_true[0, :], pos_true[1, :],
                 color="red", label="Grouth truth")
                 # color="red", marker="x", label="Grouth truth")

        # Estimated
        plt.plot(pos_est[0, :], pos_est[1, :],
                 color="blue", label="Estimated")
                 # color="blue", marker="o", label="Estimated")

        # Sliding window
        cam_pos = []
        for cam_state in cam_states:
            cam_pos.append(cam_state.p_G)
        cam_pos = np.array(cam_pos).reshape((len(cam_pos), 3)).T
        plt.plot(cam_pos[0, :], cam_pos[1, :],
                 color="green", label="Camera Poses")
                 # color="green", marker="o", label="Camera Poses")

        # Plot labels and legends
        plt.xlabel("East (m)")
        plt.ylabel("North (m)")
        plt.axis("equal")
        plt.legend(loc=0)
test_msckf.py 文件源码 项目:prototype 作者: chutsu 项目源码 文件源码 阅读 20 收藏 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 项目源码 文件源码 阅读 23 收藏 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_imu_state.py 文件源码 项目:prototype 作者: chutsu 项目源码 文件源码 阅读 23 收藏 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_features.py 文件源码 项目:prototype 作者: chutsu 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def plot_storage(self, storage):
        plt.figure()
        plt.plot(range(len(storage)), storage)
        plt.title("Num of tracks over time")
        plt.xlabel("Frame No.")
        plt.ylabel("Num of Tracks")
test_features.py 文件源码 项目:prototype 作者: chutsu 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def plot_tracked(self, tracked):
        plt.figure()
        plt.plot(range(len(tracked)), tracked)
        plt.title("Matches per Frame")
        plt.xlabel("Frame No.")
        plt.ylabel("Num of Tracks")
earth_model.py 文件源码 项目:seis_tools 作者: romaguir 项目源码 文件源码 阅读 24 收藏 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()
Q_models.py 文件源码 项目:seis_tools 作者: romaguir 项目源码 文件源码 阅读 15 收藏 0 点赞 0 评论 0
def plot_q(model='cem', r_min=0.0, r_max=6371.0, dr=1.0):

    """
    Plot a radiallysymmetric Q model.

    plot_q(model='cem', r_min=0.0, r_max=6371.0, dr=1.0):

    r_min=minimum radius [km], r_max=maximum radius [km], dr=radius increment [km]

    Currently available models (model): cem, prem, ql6
    """

    r = np.arange(r_min, r_max+dr, dr)
    q = np.zeros(len(r))

    for k in range(len(r)):

        if model=='cem':
            q[k]=q_cem(r[k])
        elif model=='ql6':
            q[k]=q_ql6(r[k])
        elif model=='prem':
            q[k]=q_prem(r[k])


    plt.plot(r,q,'k')
    plt.xlim((0.0,r_max))
    plt.xlabel('radius [km]')
    plt.ylabel('Q')
    plt.show()


###################################################################################################
#- CEM, EUMOD
###################################################################################################
pymod_sup.py 文件源码 项目:pymod 作者: pymodproject 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def xlabel(s, *args, **kwargs):
        print "Warning! Failed to import matplotlib so no axes will be labeled"
demo_mi.py 文件源码 项目:Building-Machine-Learning-Systems-With-Python-Second-Edition 作者: PacktPublishing 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _plot_mi_func(x, y):

    mi = mutual_info(x, y)
    title = "NI($X_1$, $X_2$) = %.3f" % mi
    pylab.scatter(x, y)
    pylab.title(title)
    pylab.xlabel("$X_1$")
    pylab.ylabel("$X_2$")
demo_corr.py 文件源码 项目:Building-Machine-Learning-Systems-With-Python-Second-Edition 作者: PacktPublishing 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _plot_correlation_func(x, y):

    r, p = pearsonr(x, y)
    title = "Cor($X_1$, $X_2$) = %.3f" % r
    pylab.scatter(x, y)
    pylab.title(title)
    pylab.xlabel("$X_1$")
    pylab.ylabel("$X_2$")

    f1 = scipy.poly1d(scipy.polyfit(x, y, 1))
    pylab.plot(x, f1(x), "r--", linewidth=2)
    # pylab.xticks([w*7*24 for w in [0,1,2,3,4]], ['week %i'%(w+1) for w in
    # [0,1,2,3,4]])


问题


面经


文章

微信
公众号

扫码关注公众号