Python seaborn 模块,set_style() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用seaborn.set_style()

项目:nanoQC    作者:wdecoster    | 项目源码 | 文件源码
def plot_nucleotide_diversity(ax, fqlists, invert=False):
    '''
    Create a FastQC-like "?Per base sequence content" plot
    Plot fraction of nucleotides per position
    zip will stop when shortest read is exhausted
    '''
    if invert:
        fqlists = [list(reversed(read)) for read in fqlists]
    numreads = len(fqlists)
    sns.set_style("darkgrid")
    l_A, = ax.plot(
        np.array([pos.count('A') / numreads for pos in zip(*fqlists)]), 'green', label='A')
    l_T, = ax.plot(
        np.array([pos.count('T') / numreads for pos in zip(*fqlists)]), 'red', label='T')
    l_G, = ax.plot(
        np.array([pos.count('G') / numreads for pos in zip(*fqlists)]), 'black', label='G')
    l_C, = ax.plot(
        np.array([pos.count('C') / numreads for pos in zip(*fqlists)]), 'blue', label='C')
    if invert:
        ax.set_xticklabels(-1 * ax.get_xticks().astype(int))
    return [l_A, l_T, l_G, l_C]
项目:nanoQC    作者:wdecoster    | 项目源码 | 文件源码
def plot_qual(ax, quallist, invert=False):
    '''
    Create a FastQC-like "?Per base sequence quality?" plot
    Plot average quality per position
    zip will stop when shortest read is exhausted
    '''
    sns.set_style("darkgrid")
    if invert:
        l_Q, = ax.plot(np.array([np.mean(position) for position in zip(
            *[list(reversed(read)) for read in quallist])]), 'orange', label="Quality")
        ax.set_xlabel('Position in read from end')
        ax.set_xticklabels(-1 * ax.get_xticks().astype(int))
    else:
        l_Q, = ax.plot(np.array([np.mean(position)
                                 for position in zip(*quallist)]), 'orange', label="Quality")
        ax.set_xlabel('Position in read from start')
    return l_Q
项目:keras-utilities    作者:cbaziotis    | 项目源码 | 文件源码
def on_train_begin(self, logs={}):
        sns.set_style("whitegrid")
        sns.set_style("whitegrid", {"grid.linewidth": 0.5,
                                    "lines.linewidth": 0.5,
                                    "axes.linewidth": 0.5})
        flatui = ["#9b59b6", "#3498db", "#95a5a6", "#e74c3c", "#34495e",
                  "#2ecc71"]
        sns.set_palette(sns.color_palette(flatui))
        # flatui = ["#9b59b6", "#3498db", "#95a5a6", "#e74c3c", "#34495e", "#2ecc71"]
        # sns.set_palette(sns.color_palette("Set2", 10))

        plt.ion()  # set plot to animated
        self.fig = plt.figure(
            figsize=(self.width * (1 + len(self.get_metrics(logs))),
                     self.height))  # width, height in inches

        # move it to the upper left corner
        move_figure(self.fig, 25, 25)
项目:keras-utilities    作者:cbaziotis    | 项目源码 | 文件源码
def on_train_begin(self, logs={}):
        for layer in self.get_trainable_layers():
            for param in self.parameters:
                if any(w for w in layer.weights if param in w.name.split("_")):
                    name = layer.name + "_" + param
                    self.layers_stats[name]["values"] = numpy.asarray(
                        []).ravel()
                    for s in self.stats:
                        self.layers_stats[name][s] = []

        # plt.style.use('ggplot')
        plt.ion()  # set plot to animated
        width = 3 * (1 + len(self.stats))
        height = 2 * len(self.layers_stats)
        self.fig = plt.figure(
            figsize=(width, height))  # width, height in inches
        # sns.set_style("whitegrid")
        # self.draw_plot()
项目:guesswhat    作者:GuessWhatGame    | 项目源码 | 文件源码
def __init__(self, path, games, logger, suffix):
        super(QuestionVsDialogue, self).__init__(path, self.__class__.__name__, suffix)

        q_by_d = []
        for game in games:
            q_by_d.append(len(game.questions))

        sns.set_style("whitegrid", {"axes.grid": False})


        #ratio question/dialogues
        f = sns.distplot(q_by_d, norm_hist =True, kde=False, bins=np.arange(0.5, 25.5, 1))
        f.set_xlim(0.5,25.5)
        f.set_ylim(bottom=0)

        f.set_xlabel("Number of questions", {'size':'14'})
        f.set_ylabel("Ratio of dialogues", {'size':'14'})
项目:guesswhat    作者:GuessWhatGame    | 项目源码 | 文件源码
def __init__(self, path, games, logger, suffix):
        super(WordVsQuestion, self).__init__(path, self.__class__.__name__, suffix)


        w_by_q = []
        for game in games:
            for q in game.questions:
                q = re.sub('[?]', '', q)
                words = re.findall(r'\w+', q)
                w_by_q.append(len(words))

        sns.set_style("whitegrid", {"axes.grid": False})

        # ratio question/words
        f = sns.distplot(w_by_q, norm_hist=True, kde=False, bins=np.arange(2.5, 15.5, 1), color="g")

        f.set_xlabel("Number of words", {'size': '14'})
        f.set_ylabel("Ratio of questions", {'size': '14'})
        f.set_xlim(2.5, 14.5)
        f.set_ylim(bottom=0)
项目:DAB_analyzer    作者:meklon    | 项目源码 | 文件源码
def plot_group(data_frame, path_output):
    # optional import
    import seaborn as sns
    path_output_image = os.path.join(path_output, "summary_statistics.png")

    # # Plotting swarmplot
    # plt.figure(num=None, figsize=(15, 7), dpi=120)
    # sns.set_style("whitegrid")
    #
    # plt.title('Violin plot with single measurements')
    # sns.violinplot(x="Group", y="DAB+ area", data=data_frame, inner=None)
    # sns.swarmplot(x="Group", y="DAB+ area", data=data_frame, color="w", alpha=.5)
    # plt.savefig(path_output_image)
    #
    # plt.tight_layout()

    sns.set_style("whitegrid")
    sns.set_context("talk")
    plt.figure(num=None, figsize=(15, 7), dpi=120)
    plt.ylim(0, 100)
    plt.title('Box plot')
    sns.boxplot(x="Group", y="DAB+ area, %", data=data_frame)

    plt.tight_layout()
    plt.savefig(path_output_image, dpi=300)
项目:spotlight    作者:maciejkula    | 项目源码 | 文件源码
def plot(dims, sequence, factorization):

    import matplotlib
    matplotlib.use('Agg')  # NOQA
    import matplotlib.pyplot as plt
    import seaborn as sns

    sns.set_style("darkgrid")

    plt.ylabel("Speed improvement")
    plt.xlabel("Size of embedding layers")
    plt.title("Fitting speed (1.0 = no change)")
    plt.xscale('log')

    plt.plot(dims,
             1.0 / sequence,
             label='Sequence model')
    plt.plot(dims,
             1.0 / factorization,
             label='Factorization model')
    plt.legend(loc='lower right')
    plt.savefig('speed.png')
    plt.close()
项目:ptreeopt    作者:jdherman    | 项目源码 | 文件源码
def init_plotting(w,h):
  sns.set_style('whitegrid')
  plt.rcParams['figure.figsize'] = (w,h)
  plt.rcParams['font.size'] = 13
  plt.rcParams['font.family'] = 'OfficinaSanITCBoo'
  # plt.rcParams['font.weight'] = 'bold'
  plt.rcParams['axes.labelsize'] = 1.1*plt.rcParams['font.size']
  plt.rcParams['axes.titlesize'] = 1.1*plt.rcParams['font.size']
  plt.rcParams['legend.fontsize'] = plt.rcParams['font.size']
  plt.rcParams['xtick.labelsize'] = plt.rcParams['font.size']
  plt.rcParams['ytick.labelsize'] = plt.rcParams['font.size']





# snapshots = pickle.load(open('results/hist-fit-fp/snapshots-fit-hist.pkl', 'rb'))
项目:ptreeopt    作者:jdherman    | 项目源码 | 文件源码
def init_plotting(w,h):
  sns.set_style('whitegrid')
  plt.rcParams['figure.figsize'] = (w,h)
  plt.rcParams['font.size'] = 13
  plt.rcParams['font.family'] = 'OfficinaSanITCBoo'
  # plt.rcParams['font.weight'] = 'bold'
  plt.rcParams['axes.labelsize'] = 1.1*plt.rcParams['font.size']
  plt.rcParams['axes.titlesize'] = 1.1*plt.rcParams['font.size']
  plt.rcParams['legend.fontsize'] = plt.rcParams['font.size']
  plt.rcParams['xtick.labelsize'] = plt.rcParams['font.size']
  plt.rcParams['ytick.labelsize'] = plt.rcParams['font.size']





# snapshots = pickle.load(open('results/hist-fit-fp/snapshots-fit-hist.pkl', 'rb'))
# snapshots = pickle.load(open('results/hist-tocs/snapshots-tocs-depth-3-seed-0.pkl', 'rb'))
项目:syracuse_public    作者:dssg    | 项目源码 | 文件源码
def plot_predict_proba(y_pred_probs, clf, pdf=None):
    """Plots the predict proba distribution"""
    fig, ax = plt.subplots(1, figsize=(18, 8))
    sns.set_style("white")
    sns.set_context("poster",
                    font_scale=2.25,
                    rc={"lines.linewidth": 1.25, "lines.markersize": 8})
    sns.distplot(y_pred_probs)
    plt.xlabel('predict_proba')
    plt.ylabel('frequency')
    plt.title(clf + ' proba')
    if pdf:
        pdf.savefig()
        plt.close()
    else:
        plt.show()
项目:astetik    作者:mikkokotila    | 项目源码 | 文件源码
def histogram(data,variables):

    sns.set_context("notebook", font_scale=1.5, rc={"lines.linewidth": 0})

    sns.set_style('white')

    var_length = len(variables)

    fig, axes = plt.subplots(1, var_length, figsize=(19, 5))

    for i in range(var_length):

        axes[i].hist(data[variables[i]],lw=0,color="indianred",bins=8);
        axes[i].tick_params(axis='both', which='major', pad=15)
        axes[i].set_xlabel(variables[i])
        axes[i].set_yticklabels("");

    sns.despine(left=True)
项目:hco-experiments    作者:zooniverse    | 项目源码 | 文件源码
def plot_pred_vs_image(img,preds_df,out_name):
    # function to plot predictions vs image
    f, axarr = plt.subplots(2, 1)
    plt.suptitle("ResNet50- PreTrained on ImageNet")
    axarr[0].imshow(img)
    sns.set_style("whitegrid")
    pl = sns.barplot(data = preds_df, x='Score', y='Species')
    axarr[1] = sns.barplot(data = preds_df, x='Score', y='Species',)
    axarr[0].autoscale(enable=False)
    axarr[0].get_xaxis().set_ticks([])
    axarr[0].get_yaxis().set_ticks([])
    axarr[1].autoscale(enable=False)
    gs = gridspec.GridSpec(2,1, width_ratios=[1],height_ratios=[1,0.1])
    plt.tight_layout()
    plt.savefig(out_name + '.png')


#########################
# Models
#########################

# load model
项目:artorithmia    作者:alichtner    | 项目源码 | 文件源码
def extract_blur(self, plot=False):
        """
        Calculate the variance of the 2nd derivative of the image to get blur.

        Input:  plot (bool) whether or not to show the image after Laplacian
        Output: None"""
        # do on grayscale
        # check what the mean would give instead of variance
        self.bluriness = filters.laplace(color.rgb2gray(self.image)).var()
        if plot is True:
            sns.set_style("whitegrid", {'axes.grid': False})
            self.lap = filters.laplace(color.rgb2gray(self.image))
            plt.imshow(self.lap)
            plt.title('Laplacian of {}'.format(self.short_name))
            plt.show()
            plt.imshow(self.lap)
            plt.show()
项目:artorithmia    作者:alichtner    | 项目源码 | 文件源码
def plot_hsv(image, bins=12):
    """
    Plot HSV histograms of image
    INPUT: image with HSV channels
    OUPUT: plot of HSV histograms and color spectrum
    """
    sns.set_style("whitegrid", {'axes.grid': False})
    fig = plt.figure(figsize=(12, 5))
    plt.subplots_adjust(top=2, bottom=1, wspace=.5, hspace=0)
    plt.subplot(231)
    plt.hist(image[:, :, 0].flatten(), bins=bins, color='gray')
    plt.title('Hue')
    plt.subplot(232)
    plt.hist(image[:, :, 1].flatten(), bins=bins, color='gray')
    plt.title('Saturation')
    plt.subplot(233)
    plt.hist(image[:, :, 2].flatten(), bins=bins, color='gray')
    plt.title('Value')
    plt.subplot(234)
    plt.imshow(all_hues, extent=(0, 1, 0, 0.2))
    plt.show()
项目:Penny-Dreadful-Tools    作者:PennyDreadfulMTG    | 项目源码 | 文件源码
def image(path, costs):
    ys = ['0', '1', '2', '3', '4', '5', '6', '7+', 'X']
    xs = [costs.get(k, 0) for k in ys]
    sns.set_style('white')
    sns.set(font='Concourse C3', font_scale=3)
    g = sns.barplot(ys, xs, palette=['grey'] * len(ys))
    g.axes.yaxis.set_ticklabels([])
    rects = g.patches
    sns.set(font='Concourse C3', font_scale=2)
    for rect, label in zip(rects, xs):
        if label == 0:
            continue
        height = rect.get_height()
        g.text(rect.get_x() + rect.get_width()/2, height + 0.5, label, ha='center', va='bottom')
    g.margins(y=0, x=0)
    sns.despine(left=True, bottom=True)
    g.get_figure().savefig(path, transparent=True, pad_inches=0, bbox_inches='tight')
    plt.clf() # Clear all data from matplotlib so it does not persist across requests.
    return path
项目:fitbit-analyzer    作者:5agado    | 项目源码 | 文件源码
def plotSleepValueHeatmap(intradayStats, sleepValue=1):
    sns.set_context("poster")
    sns.set_style("darkgrid")

    xTicksDiv = 20
    #stepSize = int(len(xticks)/xTicksDiv)
    stepSize = 60
    xticks = [x for x in intradayStats.columns.values]
    keptticks = xticks[::stepSize]
    xticks = ['' for _ in xticks]
    xticks[::stepSize] = keptticks
    plt.figure(figsize=(16, 4.2))
    g = sns.heatmap(intradayStats.loc[sleepValue].reshape(1,-1))
    g.set_xticklabels(xticks, rotation=45)
    g.set_yticklabels([])
    g.set_ylabel(sleepStats.SLEEP_VALUES[sleepValue])
    plt.tight_layout()
    sns.plt.show()
项目:cohorts    作者:hammerlab    | 项目源码 | 文件源码
def set_styling():
    sb.set_style("white")
    red = colors.hex2color("#bb3f3f")
    blue = colors.hex2color("#5a86ad")
    deep_colors = sb.color_palette("deep")
    green = deep_colors[1]
    custom_palette = [red, blue, green]
    custom_palette.extend(deep_colors[3:])
    sb.set_palette(custom_palette)
    mpl.rcParams.update({"figure.figsize": np.array([6, 6]),
                         "legend.fontsize": 12,
                         "font.size": 16,
                         "axes.labelsize": 16,
                         "axes.labelweight": "bold",
                         "xtick.labelsize": 16,
                         "ytick.labelsize": 16})
项目:extract    作者:dblalock    | 项目源码 | 文件源码
def makeThickSine():
    sineNoiseStd = 0
    seqLen = 750
    squareLen = seqLen / 17.
    sineLen = int(squareLen * 4)
    sine1 = synth.sines(sineLen, noiseStd=sineNoiseStd)

    sb.set_style('white')
    _, ax = plt.subplots()
    ax.plot(sine1, lw=16)
    ax.set_xlim([-squareLen, len(sine1) + squareLen])
    ax.set_ylim([-2, 2])

    sb.despine(left=True)
    plt.show()

# def makeWeirdSine(squareLen, numSquares, sineNoiseStd, **kwargs):
#   firstQuarterFrac = .4
#   length = int(squareLen * numSquares)
#   firstQuarterLen = int(firstQuarterFrac * length)
    # sine1 = synth.sines(firstQuarterLen, periods=.25, **kwargs)
    # sine2 = synth.sines(firs)
    # sine2 = synth.warpedSine(sineLen, firstHalfFrac=.67,
    #       noiseStd=sineNoiseStd)
项目:extract    作者:dblalock    | 项目源码 | 文件源码
def makeGarbageDimTs():
    np.random.seed(123)
    seqLen = 750
    squareLen = seqLen / 17.
    seq = synth.notSoRandomWalk(seqLen, std=.05,
        trendFilterLength=(seqLen // 2), lpfLength=2)

    sb.set_style('white')
    _, ax = plt.subplots()
    # color = sb.color_palette()[1]
    # ax.plot(seq, lw=4, color="#660000") # red I'm using in keynote
    ax.plot(seq, lw=4, color="#CC0000") # red I'm using in keynote
    ax.set_xlim([-squareLen, seqLen + squareLen])
    ax.set_ylim([np.min(seq) * 2, np.max(seq) * 2])

    sb.despine(left=True)
    plt.show()

# def makeMethodsWarpedTs():


# ================================================================ Better Fig1
项目:pyro    作者:uber    | 项目源码 | 文件源码
def plot_llk(train_elbo, test_elbo):
    import matplotlib.pyplot as plt
    import numpy as np
    import scipy as sp
    import seaborn as sns
    import pandas as pd
    plt.figure(figsize=(30, 10))
    sns.set_style("whitegrid")
    data = np.concatenate([np.arange(len(test_elbo))[:, sp.newaxis], -test_elbo[:, sp.newaxis]], axis=1)
    df = pd.DataFrame(data=data, columns=['Training Epoch', 'Test ELBO'])
    g = sns.FacetGrid(df, size=10, aspect=1.5)
    g.map(plt.scatter, "Training Epoch", "Test ELBO")
    g.map(plt.plot, "Training Epoch", "Test ELBO")
    plt.savefig('./vae_results/test_elbo_vae.png')
    plt.close('all')
项目:guesswhat    作者:GuessWhatGame    | 项目源码 | 文件源码
def __init__(self, path, games, logger, suffix):
        super(SuccessDialogueLength, self).__init__(path, self.__class__.__name__, suffix)

        status_list = []
        status_count = collections.defaultdict(int)
        length_list = []

        for game in games:

            length_list.append(len(game.questions))

            status_count[game.status] += 1
            status_list.append(game.status)


        success = np.array([s == "success" for s in status_list]) + 0
        failure = np.array([s == "failure" for s in status_list]) + 0
        incomp  = np.array([s == "incomplete" for s in status_list]) + 0

        sns.set_style("whitegrid", {"axes.grid": False})

        if sum(incomp) > 0:
            columns = ['Size of Dialogues', 'Success', 'Failure', 'Incomplete']
            data = np.array([length_list, success, failure, incomp]).transpose()
        else:
            columns = ['Size of Dialogues', 'Success', 'Failure']
            data = np.array([length_list, success, failure]).transpose()

        df = pd.DataFrame(data, columns=columns)
        df = df.convert_objects(convert_numeric=True)
        df = df.groupby('Size of Dialogues').sum()
        df = df.div(df.sum(axis=1), axis=0)
        #df = df.sort_values(by='Success')
        f = df.plot(kind="bar", stacked=True, width=1, alpha=0.3)

        f.set_xlim(-0.5,29.5)

        plt.xlabel("Size of Dialogues", {'size':'14'})
        plt.ylabel("Success ratio", {'size':'14'})
项目:QDREN    作者:andreamad8    | 项目源码 | 文件源码
def plot_dist(train_y,dev_y,test_y):
    import seaborn as sns
    import matplotlib.pyplot as plt
    plt.rc('text', usetex=True)
    plt.rc('font', family='Times-Roman')
    sns.set_style(style='white')
    color = sns.color_palette("Set2", 10)
    fig = plt.figure(figsize=(8,12))

    ax1 = fig.add_subplot(3, 1, 1)
    # plt.title("Label distribution",fontsize=20)
    sns.distplot(train_y,kde=False,label='Training', hist=True, norm_hist=True,color="blue")
    ax1.set_xlabel("Answer")
    ax1.set_ylabel("Frequency")
    ax1.set_xlim([0,500])
    plt.legend(loc='best')

    ax2 = fig.add_subplot(3, 1, 2)
    sns.distplot(dev_y,kde=False,label='Validation', hist=True, norm_hist=True,color="green")
    ax2.set_xlabel("Answer")
    ax2.set_ylabel("Frequency")
    ax2.set_xlim([0,500])
    plt.legend(loc='best')

    ax3 = fig.add_subplot(3, 1, 3)
    sns.distplot(test_y,kde=False,label='Test', hist=True, norm_hist=True,color="red")
    ax3.set_xlabel("Answer")
    ax3.set_ylabel("Frequency")
    ax3.set_xlim([0,500])
    plt.legend(loc='best')



    plt.savefig('checkpoints/label_dist.pdf', format='pdf', dpi=300)

    plt.show()
项目:chainladder-python    作者:jbogaardt    | 项目源码 | 文件源码
def __init__(self, my_dict):     
        sns.set_style("whitegrid")
        _ = plt.figure()
        grid_x = 1 if len(my_dict) == 1 else round(len(my_dict) / 2,0)
        grid_y = 1 if len(my_dict) == 1 else 2
        fig, ax = plt.subplots(figsize=(grid_y*15, grid_x*10))
        for num, item in enumerate(my_dict):
            _ = plt.subplot(grid_x,grid_y,num+1)
            self.__dict_plot(item)
项目:temci    作者:parttimenerd    | 项目源码 | 文件源码
def reset_plt(self):
        """ Reset the current matplotlib plot style. """
        import matplotlib.pyplot as plt
        plt.gcf().subplots_adjust(bottom=0.15)
        if Settings()["report/xkcd_like_plots"]:
            import seaborn as sns
            sns.reset_defaults()
            mpl.use("agg")
            plt.xkcd()
        else:
            import seaborn as sns
            sns.reset_defaults()
            sns.set_style("darkgrid")
            sns.set_palette(sns.color_palette("muted"))
            mpl.use("agg")
项目:pandora    作者:mikekestemont    | 项目源码 | 文件源码
def plot_mfi(self, outputfile='embeddings.pdf', nb_clusters=8, weights='NA'):
        # collect embeddings for mfi:
        X = np.asarray([self.w2v_model[w] for w in self.mfi \
                            if w in self.w2v_model], dtype='float32')
        # dimension reduction:
        tsne = TSNE(n_components=2)
        coor = tsne.fit_transform(X) # unsparsify

        plt.clf()
        sns.set_style('dark')
        sns.plt.rcParams['axes.linewidth'] = 0.4
        fig, ax1 = sns.plt.subplots()  

        labels = self.mfi
        # first plot slices:
        x1, x2 = coor[:,0], coor[:,1]
        ax1.scatter(x1, x2, 100, edgecolors='none', facecolors='none')
        # clustering on top (add some colouring):
        clustering = AgglomerativeClustering(linkage='ward',
                            affinity='euclidean', n_clusters=nb_clusters)
        clustering.fit(coor)
        # add names:
        for x, y, name, cluster_label in zip(x1, x2, labels, clustering.labels_):
            ax1.text(x, y, name, ha='center', va="center",
                     color=plt.cm.spectral(cluster_label / 10.),
                     fontdict={'family': 'Arial', 'size': 8})
        # control aesthetics:
        ax1.set_xlabel('')
        ax1.set_ylabel('')
        ax1.set_xticklabels([])
        ax1.set_xticks([])
        ax1.set_yticklabels([])
        ax1.set_yticks([])
        sns.plt.savefig(outputfile, bbox_inches=0)
项目:Dataquest    作者:ustutz    | 项目源码 | 文件源码
def main():
        seaborn_Seaborn_Module.set_style("dark")
        housing_2013 = pandas_Pandas_Module.read_csv("../Hud_2013.csv")
        cols = ['AGE1', 'FMR', 'TOTSAL']
        filtered_housing_2013 = housing_2013[cols]
        filtered_housing_2013.hist(column='AGE1', bins=5)
        filtered_housing_2013.hist(column='AGE1', bins=10)
        matplotlib_pyplot_Pyplot_Module.show()
项目:Dataquest    作者:ustutz    | 项目源码 | 文件源码
def main():
        seaborn_Seaborn_Module.set_style("dark")
        housing_2013 = pandas_Pandas_Module.read_csv("../Hud_2013.csv")
        cols = ['AGE1', 'FMR', 'TOTSAL']
        filtered_housing_2013 = housing_2013[cols]
        filtered_housing_2013.hist(column='FMR', bins=20)
        matplotlib_pyplot_Pyplot_Module.show()
项目:spotlight    作者:maciejkula    | 项目源码 | 文件源码
def plot_results(model, movielens, amazon):

    sns.set_style("darkgrid")

    for name, result in (('Movielens',
                          movielens), ('Amazon', amazon)):

        print('Dataset: {}'.format(name))

        (compression_ratio,
         mrr,
         elapsed) = process_results(result, verbose=True)

        plt.plot(compression_ratio, mrr,
                 label=name)

    plt.ylabel("MRR ratio to baseline")
    plt.xlabel("Compression ratio")
    plt.title("Compression ratio vs MRR ratio")

    plt.legend(loc='lower right')
    plt.savefig('{}_plot.png'.format(model))
    plt.close()

    for name, result in (('Movielens',
                          movielens), ('Amazon', amazon)):

        (compression_ratio,
         mrr,
         elapsed) = process_results(result)

        plt.plot(compression_ratio, elapsed,
                 label=name)

    plt.ylabel("Time ratio to baseline")
    plt.xlabel("Compression ratio")
    plt.title("Compression ratio vs time ratio")
    plt.legend(loc='lower right')

    plt.savefig('{}_time.png'.format(model))
    plt.close()
项目:score_card_base_python    作者:zzstrwolf    | 项目源码 | 文件源码
def plot_br_chart(self,column):
        if type(self.woe_dicts[column].items()[0][0]) == str:
            woe_lists = sorted(self.woe_dicts[column].items(), key = self.sort_dict)
        else:
            woe_lists = sorted(self.woe_dicts[column].items(),key = lambda item:item[0])
        sns.set_style(rc={"axes.facecolor": "#EAEAF2",
                "axes.edgecolor": "#EAEAF2",
                "axes.linewidth": 1,
                "grid.color": "white",})
        tick_label = [i[0] for i in woe_lists]
        counts = [i[1][1] for i in woe_lists]
        br_data = [i[1][2] for i in woe_lists]
        x = range(len(counts))
        fig, ax1 = plt.subplots(figsize=(12,8))
        my_palette = sns.color_palette(n_colors=100)
        sns.barplot(x,counts,ax=ax1,palette=sns.husl_palette(n_colors=20,l=.7))
        plt.xticks(x,tick_label,rotation = 30,fontsize=12)
        plt.title(column,fontsize=18)
        ax1.set_ylabel('count',fontsize=15)
        ax1.tick_params('y',direction='in',length=6, width=0.5, labelsize=12)
        #ax1.bar(x,counts,tick_label = tick_label,color = 'y',align = 'center')
        #ax1.bar(x,counts,color = 'y',align = 'center')

        ax2 = ax1.twinx()
        ax2.plot(x,br_data,color='black')
        ax2.set_ylabel('bad rate',fontsize=15)
        ax2.tick_params('y',direction='in',length=6, width=0.5, labelsize=12)
        plot_margin = 0.25
        x0, x1, y0, y1 = ax1.axis()
        ax1.axis((x0 - plot_margin,
              x1 + plot_margin,
              y0 - 0,
              y1 * 1.1))
        plt.show()
项目:ptreeopt    作者:jdherman    | 项目源码 | 文件源码
def init_plotting():
  sns.set_style('whitegrid')

  sns.set_style('whitegrid')
  plt.rcParams['figure.figsize'] = (12, 8)
  plt.rcParams['font.size'] = 13
  plt.rcParams['font.family'] = 'OfficinaSanITCBoo'
  # plt.rcParams['font.weight'] = 'bold'
  plt.rcParams['axes.labelsize'] = 1.1*plt.rcParams['font.size']
  plt.rcParams['axes.titlesize'] = 1.1*plt.rcParams['font.size']
  plt.rcParams['legend.fontsize'] = plt.rcParams['font.size']
  plt.rcParams['xtick.labelsize'] = plt.rcParams['font.size']
  plt.rcParams['ytick.labelsize'] = plt.rcParams['font.size']
项目:ptreeopt    作者:jdherman    | 项目源码 | 文件源码
def init_plotting(w,h):
  sns.set_style('whitegrid')
  plt.rcParams['figure.figsize'] = (w,h)
  plt.rcParams['font.size'] = 8
  plt.rcParams['font.family'] = 'Source Sans Pro'
  # plt.rcParams['font.weight'] = 'bold'
  plt.rcParams['axes.labelsize'] = 1.1*plt.rcParams['font.size']
  plt.rcParams['axes.titlesize'] = 1.1*plt.rcParams['font.size']
  plt.rcParams['legend.fontsize'] = plt.rcParams['font.size']
  plt.rcParams['xtick.labelsize'] = plt.rcParams['font.size']
  plt.rcParams['ytick.labelsize'] = plt.rcParams['font.size']
项目:ptreeopt    作者:jdherman    | 项目源码 | 文件源码
def init_plotting(w,h):
  sns.set_style('whitegrid')
  plt.rcParams['figure.figsize'] = (w,h)
  plt.rcParams['font.size'] = 13
  plt.rcParams['font.family'] = 'OfficinaSanITCBoo'
  # plt.rcParams['font.weight'] = 'bold'
  plt.rcParams['axes.labelsize'] = 1.1*plt.rcParams['font.size']
  plt.rcParams['axes.titlesize'] = 1.1*plt.rcParams['font.size']
  plt.rcParams['legend.fontsize'] = plt.rcParams['font.size']
  plt.rcParams['xtick.labelsize'] = plt.rcParams['font.size']
  plt.rcParams['ytick.labelsize'] = plt.rcParams['font.size']


# init_plotting(7,4)
项目:ptreeopt    作者:jdherman    | 项目源码 | 文件源码
def init_plotting(w,h):
  sns.set_style('whitegrid')
  plt.rcParams['figure.figsize'] = (w,h)
  plt.rcParams['font.size'] = 13
  plt.rcParams['font.family'] = 'OfficinaSanITCBoo'
  # plt.rcParams['font.weight'] = 'bold'
  plt.rcParams['axes.labelsize'] = 1.1*plt.rcParams['font.size']
  plt.rcParams['axes.titlesize'] = 1.1*plt.rcParams['font.size']
  plt.rcParams['legend.fontsize'] = plt.rcParams['font.size']
  plt.rcParams['xtick.labelsize'] = plt.rcParams['font.size']
  plt.rcParams['ytick.labelsize'] = plt.rcParams['font.size']
项目:ptreeopt    作者:jdherman    | 项目源码 | 文件源码
def init_plotting(w,h):
  sns.set_style('whitegrid')
  plt.rcParams['figure.figsize'] = (w,h)
  plt.rcParams['font.size'] = 13
  plt.rcParams['font.family'] = 'OfficinaSanITCBoo'
  # plt.rcParams['font.weight'] = 'bold'
  plt.rcParams['axes.labelsize'] = 1.1*plt.rcParams['font.size']
  plt.rcParams['axes.titlesize'] = 1.1*plt.rcParams['font.size']
  plt.rcParams['legend.fontsize'] = plt.rcParams['font.size']
  plt.rcParams['xtick.labelsize'] = plt.rcParams['font.size']
  plt.rcParams['ytick.labelsize'] = plt.rcParams['font.size']
项目:ptreeopt    作者:jdherman    | 项目源码 | 文件源码
def init_plotting(w,h):
  sns.set_style('whitegrid')
  plt.rcParams['figure.figsize'] = (w,h)
  plt.rcParams['font.size'] = 13
  plt.rcParams['font.family'] = 'OfficinaSanITCBoo'
  # plt.rcParams['font.weight'] = 'bold'
  plt.rcParams['axes.labelsize'] = 1.1*plt.rcParams['font.size']
  plt.rcParams['axes.titlesize'] = 1.1*plt.rcParams['font.size']
  plt.rcParams['legend.fontsize'] = plt.rcParams['font.size']
  plt.rcParams['xtick.labelsize'] = plt.rcParams['font.size']
  plt.rcParams['ytick.labelsize'] = plt.rcParams['font.size']
项目:ptreeopt    作者:jdherman    | 项目源码 | 文件源码
def init_plotting(w,h):
  sns.set_style('whitegrid')
  plt.rcParams['figure.figsize'] = (w,h)
  plt.rcParams['font.size'] = 13
  plt.rcParams['font.family'] = 'OfficinaSanITCBoo'
  # plt.rcParams['font.weight'] = 'bold'
  plt.rcParams['axes.labelsize'] = 1.1*plt.rcParams['font.size']
  plt.rcParams['axes.titlesize'] = 1.1*plt.rcParams['font.size']
  plt.rcParams['legend.fontsize'] = plt.rcParams['font.size']
  plt.rcParams['xtick.labelsize'] = plt.rcParams['font.size']
  plt.rcParams['ytick.labelsize'] = plt.rcParams['font.size']


# init_plotting(7,4)
项目:ptreeopt    作者:jdherman    | 项目源码 | 文件源码
def init_plotting(w,h):
  sns.set_style('whitegrid')
  plt.rcParams['figure.figsize'] = (w,h)
  plt.rcParams['font.size'] = 13
  plt.rcParams['font.family'] = 'OfficinaSanITCBoo'
  # plt.rcParams['font.weight'] = 'bold'
  plt.rcParams['axes.labelsize'] = 1.1*plt.rcParams['font.size']
  plt.rcParams['axes.titlesize'] = 1.1*plt.rcParams['font.size']
  plt.rcParams['legend.fontsize'] = plt.rcParams['font.size']
  plt.rcParams['xtick.labelsize'] = plt.rcParams['font.size']
  plt.rcParams['ytick.labelsize'] = plt.rcParams['font.size']
项目:augur    作者:nextstrain    | 项目源码 | 文件源码
def plot_frequencies(flu, gene, mutation=None, plot_regions=None, all_muts=False, ax=None, **kwargs):
    import seaborn as sns
    sns.set_style('whitegrid')
    cols = sns.color_palette()
    linestyles = ['-', '--', '-.', ':']
    if plot_regions is None:
        plot_regions=regions
    pivots = flu.pivots
    if ax is None:
        plt.figure()
        ax=plt.subplot(111)
    if type(mutation)==int:
        mutations = [x for x,freq in flu.mutation_frequencies[('global', gene)].iteritems()
                     if (x[0]==mutation)&(freq[0]<0.5 or all_muts)]
    elif mutation is not None:
        mutations = [mutation]
    else:
        mutations=None

    if mutations is None:
        for ri, region in enumerate(plot_regions):
            count=flu.mutation_frequency_counts[region]
            plt.plot(pivots, count, c=cols[ri%len(cols)], label=region)
    else:
        print("plotting mutations", mutations)
        for ri,region in enumerate(plot_regions):
            for mi,mut in enumerate(mutations):
                if mut in flu.mutation_frequencies[(region, gene)]:
                    freq = flu.mutation_frequencies[(region, gene)][mut]
                    err = flu.mutation_frequency_confidence[(region, gene)][mut]
                    c=cols[ri%len(cols)]
                    label_str = str(mut[0]+1)+mut[1]+', '+region
                    plot_trace(ax, pivots, freq, err, c=c,
                        ls=linestyles[mi%len(linestyles)],label=label_str, **kwargs)
                else:
                    print(mut, 'not found in region',region)
    ax.ticklabel_format(useOffset=False)
    ax.legend(loc=2)
项目:augur    作者:nextstrain    | 项目源码 | 文件源码
def plot_sequence_count(flu, fname=None, fs=12):
    # make figure with region counts
    import seaborn as sns
    date_bins = pivots_to_dates(flu.pivots)
    sns.set_style('ticks')
    region_label = {'global': 'Global', 'NA': 'N America', 'AS': 'Asia', 'EU': 'Europe', 'OC': 'Oceania'}
    regions_abbr = ['global', 'NA', 'AS', 'EU', 'OC']
    region_colors = {r:col for r, col in zip(regions_abbr,
                                             sns.color_palette(n_colors=len(regions_abbr)))}
    fig, ax = plt.subplots(figsize=(8, 3))
    count_by_region = flu.mutation_frequency_counts
    drop = 3
    tmpcounts = np.zeros(len(flu.pivots[drop:]))
    plt.bar(date_bins[drop:], count_by_region['global'][drop:], width=18, \
            linewidth=0, label="Other", color="#bbbbbb", clip_on=False)
    for region in region_groups:
        if region!='global':
            plt.bar(date_bins[drop:], count_by_region[region][drop:],
                    bottom=tmpcounts, width=18, linewidth=0,
                    label=region_label[region], color=region_colors[region], clip_on=False)
            tmpcounts += count_by_region[region][drop:]
    make_date_ticks(ax, fs=fs)
    ax.set_ylabel('Sample count')
    ax.legend(loc=3, ncol=1, bbox_to_anchor=(1.02, 0.53))
    plt.subplots_adjust(left=0.1, right=0.82, top=0.94, bottom=0.22)
    sns.despine()
    if fname is not None:
        plt.savefig(fname)
项目:microbiomeHD    作者:cduvallet    | 项目源码 | 文件源码
def plot_aucs(aucs, x_col, y_col, groupby_col, colors):
    """
    Scatter plot aucs[x_col] vs aucs[y_col], colored by colors[groupby_col]

    Parameters
    ----------
    aucs : pandas DataFrame
        has x_col, y_col, and groupby_col
    x_col, y_col, groupby_col : str
    colors : dict
        values in groupby_col: color to plot
    """
    sns.set_style('white')
    fig, ax = plt.subplots(figsize=(4,3))
    ax.plot([0, 1], [0, 1], '--', c='0.95')
    ax.plot([0.5, 0.5], [0, 1], '--', c='0.95')
    ax.plot([0, 1], [0.5, 0.5], '--', c='0.95')
    for g, subdf in aucs.groupby(groupby_col):
        if g == 'cdi':
            label = 'diarrhea'
        else:
            label = g.upper()
        ax.scatter(subdf[x_col], subdf[y_col], c=colors[g], label=label)
    ax.set_xlim([0, 1])
    ax.set_ylim([0, 1])
    fig.tight_layout()
    # Shrink current axis by 20%
    box = ax.get_position()
    ax.set_position([box.x0, box.y0, box.width * 0.8, box.height])
    # Put a legend to the right of the current axis
    lgd = ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))
    return fig, ax, lgd
项目:arXivTimesIndicator    作者:chakki-works    | 项目源码 | 文件源码
def save_bar_graph(x, y, file_name):
    plt.clf()
    sns.set_style("whitegrid")
    ax = sns.barplot(x=x, y=y)
    for item in ax.get_xticklabels():
        item.set_rotation(15)
    plt.savefig(file_name)
项目:arXivTimesIndicator    作者:chakki-works    | 项目源码 | 文件源码
def save_graph_with_icon(x, y, images, file_name):
    plt.clf()
    sns.set_style("whitegrid")
    ax = sns.barplot(x=x, y=y, ci=None)

    # erase ticks
    ax.get_xaxis().set_ticklabels([], fontsize=45)  # expand label size by fontsize parameter
    TICK_POS = -0.25
    SIZE_IN_TICK = 1

    scale = ax.transData.transform((1, 1)) - ax.transData.transform((0, 0))
    x_scale = scale[0] / scale[1]

    for i, _x in enumerate(x):
        label_x = _x  # adjustment is not needed in saved file
        left = label_x - (SIZE_IN_TICK / x_scale / 2)
        down = TICK_POS - SIZE_IN_TICK
        right = label_x + (SIZE_IN_TICK / x_scale / 2)
        top = TICK_POS
        leftDown = ax.transData.transform((left, down))
        rightUpper = ax.transData.transform((right, top))
        bbox_image = BboxImage(Bbox([leftDown, rightUpper]),
                               norm=None,
                               origin=None,
                               clip_on=False
                               )
        bbox_image.set_data(images[i])
        ax.add_artist(bbox_image)
    plt.savefig(file_name)
项目:astetik    作者:mikkokotila    | 项目源码 | 文件源码
def kde(x,y,title='',color='YlGnBu',xscale='linear',yscale='linear'):

    sns.set_style('white')
    sns.set_context('notebook', font_scale=1, rc={"lines.linewidth": 0.5})
    g = sns.kdeplot(x,y,shade=True, cut=2, cmap=color, shade_lowest=False, legend=True, set_title="test")
    plt.tick_params(axis='both', which='major', pad=10)
    sns.plt.title(title)

    g.set(xscale=xscale)
    g.set(yscale=yscale)

    sns.despine()
项目:astetik    作者:mikkokotila    | 项目源码 | 文件源码
def regression(data,x,y,xscale='linear',yscale='linear'):


    sns.set_context("notebook", font_scale=.8, rc={"lines.linewidth": 0})
    sns.set_style('white')

    g = sns.regplot(x=x, y=y, data=data)

    plt.tick_params(axis='both', which='major', pad=10)

    g.set(xscale=xscale)
    g.set(yscale=yscale)

    sns.despine()
项目:datawatch    作者:WideOpen    | 项目源码 | 文件源码
def update_graph(dff):
    sns.set_style("white")
    sns.set_style("ticks")

    sns.set_context("talk")
    dff.ix[::10].plot("date", "overdue", figsize=(7, 4), lw=3)
    onemonth = datetime.timedelta(30)
    plt.xlim(dff.date.min(), dff.date.max()+onemonth)
    plt.ylabel("Overdue dataset")
    plt.xlabel("Date")
    plt.savefig("docs/graph.png")
项目:pygcam    作者:JGCRI    | 项目源码 | 文件源码
def setupPlot(context="talk", style="white", font_scale=1.0):
    sns.set_context(context, font_scale=font_scale)
    sns.set_style(style)
项目:artorithmia    作者:alichtner    | 项目源码 | 文件源码
def show_image(self):
        """
        Method to plot the image and attributes.

        Input:  None
        Output: None
        """
        print self.__str__()
        sns.set_style("whitegrid", {'axes.grid': False})
        plt.imshow(self.image)
        plt.show()
项目:jira-metrics-extract    作者:rnwolf    | 项目源码 | 文件源码
def set_style(style="darkgrid"):
    sns.set_style(style)
项目:rnnlab    作者:phueb    | 项目源码 | 文件源码
def make_probes_ba_traj_fig(models1, models2=None, palette=None):  # TODO ylim
    """
    Returns fig showing trajectory of probes balanced accuracy
    """
    start = time.time()
    sns.set_style('white')
    # load data
    xys = []
    model_groups = [models1] if models2 is None else [models1, models2]
    for n, models in enumerate(model_groups):
        model_probes_ba_trajs = []
        for nn, model in enumerate(models):
            model_probes_ba_trajs.append(model.get_traj('probes_ba'))
        x = models[0].get_data_step_axis()
        traj_mat = np.asarray([traj[:len(x)] for traj in model_probes_ba_trajs])  # all trajs are truncated to shortest
        y = np.mean(traj_mat, axis=0)
        sem = [stats.sem(model_probes_bas) for model_probes_bas in traj_mat.T]
        xys.append((x, y, sem))
    # fig
    fig, ax = plt.subplots(figsize=(FigsConfigs.MAX_FIG_WIDTH, 3))
    ax.set_ylim([50, 75])
    ax.set_xlabel('Mini Batch', fontsize=FigsConfigs.AXLABEL_FONT_SIZE)
    ax.set_ylabel('Probes Balanced Accuracy', fontsize=FigsConfigs.AXLABEL_FONT_SIZE)
    ax.spines['right'].set_visible(False)
    ax.spines['top'].set_visible(False)
    ax.tick_params(axis='both', which='both', top='off', right='off')
    ax.xaxis.set_major_formatter(FuncFormatter(human_format))
    ax.yaxis.grid(True)
    # plot
    for (x, y, sem) in xys:
        color = next(palette) if palette is not None else 'black'
        ax.plot(x, y, '-', linewidth=FigsConfigs.LINEWIDTH, color=color)
        ax.fill_between(x, np.add(y, sem), np.subtract(y, sem), alpha=FigsConfigs.FILL_ALPHA, color='grey')
    plt.tight_layout()
    print('{} completed in {:.1f} secs'.format(sys._getframe().f_code.co_name, time.time() - start))
    return fig