Python seaborn.distplot() Examples

The following are 30 code examples of seaborn.distplot(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module seaborn , or try the search function .
Example #1
Source File: plotter.py    From message-analyser with MIT License 7 votes vote down vote up
def distplot_messages_per_month(msgs, path_to_save):
    sns.set(style="whitegrid")

    start_date = msgs[0].date.date()
    (xticks, xticks_labels, xlabel) = _get_xticks(msgs)

    ax = sns.distplot([(msg.date.date() - start_date).days for msg in msgs],
                      bins=xticks + [(msgs[-1].date.date() - start_date).days], color="m", kde=False)
    ax.set_xticklabels(xticks_labels)
    ax.set(xlabel=xlabel, ylabel="messages")
    ax.margins(x=0)

    plt.xticks(xticks, rotation=65)
    plt.tight_layout()
    fig = plt.gcf()
    fig.set_size_inches(11, 8)

    fig.savefig(os.path.join(path_to_save, distplot_messages_per_month.__name__ + ".png"), dpi=500)
    # plt.show()
    log_line(f"{distplot_messages_per_month.__name__} was created.")
    plt.close("all") 
Example #2
Source File: plotter.py    From message-analyser with MIT License 7 votes vote down vote up
def distplot_messages_per_day(msgs, path_to_save):
    sns.set(style="whitegrid")

    data = stools.get_messages_per_day(msgs)

    max_day_len = len(max(data.values(), key=len))
    ax = sns.distplot([len(day) for day in data.values()], bins=list(range(0, max_day_len, 50)) + [max_day_len],
                      color="m", kde=False)
    ax.set(xlabel="messages", ylabel="days")
    ax.margins(x=0)

    fig = plt.gcf()
    fig.set_size_inches(11, 8)

    fig.savefig(os.path.join(path_to_save, distplot_messages_per_day.__name__ + ".png"), dpi=500)
    # plt.show()
    log_line(f"{distplot_messages_per_day.__name__} was created.")
    plt.close("all") 
Example #3
Source File: plotter.py    From message-analyser with MIT License 7 votes vote down vote up
def distplot_messages_per_hour(msgs, path_to_save):
    sns.set(style="whitegrid")

    ax = sns.distplot([msg.date.hour for msg in msgs], bins=range(25), color="m", kde=False)
    ax.set_xticklabels(stools.get_hours())
    ax.set(xlabel="hour", ylabel="messages")
    ax.margins(x=0)

    plt.xticks(range(24), rotation=65)
    plt.tight_layout()
    fig = plt.gcf()
    fig.set_size_inches(11, 8)

    fig.savefig(os.path.join(path_to_save, distplot_messages_per_hour.__name__ + ".png"), dpi=500)
    # plt.show()
    log_line(f"{distplot_messages_per_hour.__name__} was created.")
    plt.close("all") 
Example #4
Source File: plot_functions.py    From idea_relations with MIT License 7 votes vote down vote up
def joint_plot(x, y, xlabel=None,
               ylabel=None, xlim=None, ylim=None,
               loc="best", color='#0485d1',
               size=8, markersize=50, kind="kde",
               scatter_color="r"):
    with sns.axes_style("darkgrid"):
        if xlabel and ylabel:
            g = SubsampleJointGrid(xlabel, ylabel,
                    data=DataFrame(data={xlabel: x, ylabel: y}),
                    space=0.1, ratio=2, size=size, xlim=xlim, ylim=ylim)
        else:
            g = SubsampleJointGrid(x, y, size=size,
                    space=0.1, ratio=2, xlim=xlim, ylim=ylim)
        g.plot_joint(sns.kdeplot, shade=True, cmap="Blues")
        g.plot_sub_joint(plt.scatter, 1000, s=20, c=scatter_color, alpha=0.3)
        g.plot_marginals(sns.distplot, kde=False, rug=False)
        g.annotate(ss.pearsonr, fontsize=25, template="{stat} = {val:.2g}\np = {p:.2g}")
        g.ax_joint.set_yticklabels(g.ax_joint.get_yticks())
        g.ax_joint.set_xticklabels(g.ax_joint.get_xticks())
    return g 
Example #5
Source File: plotting.py    From pySCENIC with GNU General Public License v3.0 7 votes vote down vote up
def plot_binarization(auc_mtx: pd.DataFrame, regulon_name: str, threshold: float, bins: int=200, ax=None) -> None:
    """
    Plot the "binarization" process for the given regulon.

    :param auc_mtx: The dataframe with the AUC values for all cells and regulons (n_cells x n_regulons).
    :param regulon_name: The name of the regulon.
    :param bins: The number of bins to use in the AUC histogram.
    :param threshold: The threshold to use for binarization.
    """
    if ax is None:
        ax=plt.gca()
    sns.distplot(auc_mtx[regulon_name], ax=ax, norm_hist=True, bins=bins)

    ylim = ax.get_ylim()
    ax.plot([threshold]*2, ylim, 'r:')
    ax.set_ylim(ylim)
    ax.set_xlabel('AUC')
    ax.set_ylabel('#')
    ax.set_title(regulon_name) 
Example #6
Source File: analysis.py    From dl-eeg-review with MIT License 6 votes vote down vote up
def _plot_results_accuracy_diff_distr(results_df, save_cfg):
    """Plot the distribution of difference in accuracy.
    """
    fig, ax = plt.subplots(figsize=(save_cfg['text_width'], 
                                    save_cfg['text_height'] * 0.5))
    sns.distplot(results_df['acc_diff'], kde=False, rug=True, ax=ax)
    ax.set_xlabel('Accuracy difference')
    ax.set_ylabel('Number of studies')
    plt.tight_layout()

    if save_cfg is not None:
        savename = 'reported_accuracy_diff_distr'
        fname = os.path.join(save_cfg['savepath'], savename)
        fig.savefig(fname + '.' + save_cfg['format'], **save_cfg)

    return ax 
Example #7
Source File: run.py    From blood-glucose-prediction with GNU General Public License v3.0 6 votes vote down vote up
def plot_target_distribution(y_test, cfg):
    if 'xml_path' in cfg['dataset']:
        basename = os.path.basename(cfg['dataset']['xml_path'])
        patient_id = basename.split('-')[0]
    else:
        patient_id = ""
    if 'scale' in cfg['dataset']:
        scale = float(cfg['dataset']['scale'])
    else:
        scale = 1.0

    plt.figure()
    sns.distplot(y_test.flatten()/scale, kde=False, norm_hist=True)
    save_path = os.path.join(cfg['train']['artifacts_path'], "{}_dist_plot.pdf".format(patient_id))
    print("saving plot to: ", save_path)
    plt.savefig(save_path, dpi=300) 
Example #8
Source File: stock_visualizer.py    From stock-analysis with MIT License 6 votes vote down vote up
def histogram(self, column, **kwargs):
        """
        Generate the histogram of a given column for all assets in group.

        Parameters:
            - column: The name of the column to visualize.
            - kwargs: Additional keyword arguments to pass down
                      to the plotting function.

        Returns:
            A matplotlib Axes object.
        """
        fig, axes = self._get_layout()
        for ax, (name, data) in zip(axes, self.data.groupby(self.group_by)):
            sns.distplot(data[column], ax=ax, axlabel=f'{name} - {column}')
        return axes 
Example #9
Source File: model_visualizer.py    From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License 6 votes vote down vote up
def plot_tensor(tensor, ax, name, config, plot_type="kde"):
    ax.set_title(name, fontsize="small")
    ax.xaxis.set_tick_params(labelsize=6)
    ax.yaxis.set_tick_params(labelsize=6)
    # import ipdb as pdb; pdb.set_trace()
    if config["quantization"].lower() == "fixed":
        i_w = config["weight_i_width"] 
        f_w = config["weight_f_width"] 
        if plot_type.lower()=="kde":
            sns.distplot(quant.to_fixed_point(quant.to_nearest_power_of_two(tensor.cpu()), i_w, f_w).cpu().detach().numpy(), ax=ax, kde_kws={"color": "r"})
        elif plot_type.lower()=="hist":
            sns.distplot(quant.to_fixed_point(quant.to_nearest_power_of_two(tensor.cpu()), i_w, f_w).cpu().detach().numpy(), ax=ax, kde=False, hist=True, rug=True, norm_hist=False, bins=100)
        else:
            print("Unsupported plot type")
    elif config["quantization"].lower() == "normal":
        if plot_type.lower()=="kde":
            sns.distplot(tensor.detach().numpy(), ax=ax, kde_kws={"color": "r"})
        elif plot_type.lower()=="hist":
            sns.distplot(tensor.detach().numpy(), ax=ax, kde=False, hist=True, rug=True, norm_hist=False, bins=100)
        else:
            print("Unsupported plot type") 
Example #10
Source File: visualize_traindata.py    From Supply-demand-forecasting with MIT License 6 votes vote down vote up
def traffic_districution(self):
        data_dir = g_singletonDataFilePath.getTrainDir()
        df = self.load_trafficdf(data_dir)
        print df['traffic'].describe()
#         sns.distplot(self.gapdf['gap'],kde=False, bins=100);
        df['traffic'].plot(kind='hist', bins=100)
        plt.xlabel('Traffic')
        plt.title('Histogram of Traffic')

        return
#     def disp_gap_bydistrict(self, disp_ids = np.arange(34,67,1), cls1 = 'start_district_id', cls2 = 'time_id'):
# #         disp_ids = np.arange(1,34,1)
#         plt.figure()
#         by_district = self.gapdf.groupby(cls1)
#         size = len(disp_ids)
# #         size = len(by_district)
#         col_len = row_len = math.ceil(math.sqrt(size))
#         count = 1
#         for name, group in by_district:
#             if not name in disp_ids:
#                 continue
#             plt.subplot(row_len, col_len, count)
#             group.groupby(cls2)['gap'].mean().plot()
#             count += 1   
#         return 
Example #11
Source File: demos.py    From bayesian_bootstrap with MIT License 6 votes vote down vote up
def plot_mean_bootstrap_exponential_readme():
    X = np.random.exponential(7, 4)
    classical_samples = [np.mean(resample(X)) for _ in range(10000)]
    posterior_samples = mean(X, 10000)
    l, r = highest_density_interval(posterior_samples)
    classical_l, classical_r = highest_density_interval(classical_samples)
    plt.subplot(2, 1, 1)
    plt.title('Bayesian Bootstrap of mean')
    sns.distplot(posterior_samples, label='Bayesian Bootstrap Samples')
    plt.plot([l, r], [0, 0], linewidth=5.0, marker='o', label='95% HDI')
    plt.xlim(-1, 18)
    plt.legend()
    plt.subplot(2, 1, 2)
    plt.title('Classical Bootstrap of mean')
    sns.distplot(classical_samples, label='Classical Bootstrap Samples')
    plt.plot([classical_l, classical_r], [0, 0], linewidth=5.0, marker='o', label='95% HDI')
    plt.xlim(-1, 18)
    plt.legend()
    plt.savefig('readme_exponential.png', bbox_inches='tight') 
Example #12
Source File: visualizations.py    From Brancher with MIT License 6 votes vote down vote up
def plot_posterior_histogram(model, variables, number_samples=300): #TODO: fix code duplication

    # Get samples
    sample = model.get_sample(number_samples)
    post_sample = model.get_posterior_sample(number_samples)

    # Join samples
    sample["Mode"] = "Prior"
    post_sample["Mode"] = "Posterior"
    subsample = sample[variables + ["Mode"]]
    post_subsample = post_sample[variables + ["Mode"]]
    joint_subsample = subsample.append(post_subsample)

    # Plot posterior
    warnings.filterwarnings('ignore')
    g = sns.PairGrid(joint_subsample, hue="Mode")
    g = g.map_offdiag(sns.distplot)
    g = g.map_diag(sns.distplot)
    g = g.add_legend()
    warnings.filterwarnings('default') 
Example #13
Source File: demos.py    From bayesian_bootstrap with MIT License 6 votes vote down vote up
def plot_mean_bootstrap():
    X = [-1, 0, 1]
    posterior_samples = mean(X, 10000)
    sns.distplot(posterior_samples)
    classical_samples = [np.mean(resample(X)) for _ in range(10000)]
    sns.distplot(classical_samples)
    plt.show() 
Example #14
Source File: visualization.py    From Supply-demand-forecasting with MIT License 6 votes vote down vote up
def disp_gap_bydate(self):
        gaps_mean = self.gapdf.groupby('time_date')['gap'].mean()
        gaps_mean.plot(kind='bar')
        plt.ylabel('Mean of gap')
        plt.title('Date/Gap Correlation')
#         for i in gaps_mean.index:
#             plt.plot([i,i], [0, gaps_mean[i]], 'k-')
        plt.show()
        return
   
#     def drawGapDistribution(self):
#         self.gapdf[self.gapdf['gapdf'] < 10]['gapdf'].hist(bins=50)
# #         sns.distplot(self.gapdf['gapdf']);
# #         sns.distplot(self.gapdf['gapdf'], hist=True, kde=False, rug=False)
# #         plt.hist(self.gapdf['gapdf'])
#         plt.show()
#         return
#     def drawGapCorrelation(self):
#         _, (ax1, ax2) = plt.subplots(nrows=2, ncols=1)
#         res = self.gapdf.groupby('start_district_id')['gapdf'].sum()
#         ax1.bar(res.index, res.values)
#         res = self.gapdf.groupby('time_slotid')['gapdf'].sum()
#         ax2.bar(res.index.map(lambda x: x[11:]), res.values)
#         plt.show()
#         return 
Example #15
Source File: model_visualizer.py    From U-Net-Fixed-Point-Quantization-for-Medical-Image-Segmentation with MIT License 6 votes vote down vote up
def plot_tensor(tensor, ax, name, config, plot_type="kde"):
    ax.set_title(name, fontsize="small")
    ax.xaxis.set_tick_params(labelsize=6)
    ax.yaxis.set_tick_params(labelsize=6)
    # import ipdb as pdb; pdb.set_trace()
    if config["quantization"].lower() == "fixed":
        i_w = config["weight_i_width"] 
        f_w = config["weight_f_width"] 
        if plot_type.lower()=="kde":
            sns.distplot(quant.to_fixed_point(quant.to_nearest_power_of_two(tensor.cpu()), i_w, f_w).cpu().detach().numpy(), ax=ax, kde_kws={"color": "r"})
        elif plot_type.lower()=="hist":
            sns.distplot(quant.to_fixed_point(quant.to_nearest_power_of_two(tensor.cpu()), i_w, f_w).cpu().detach().numpy(), ax=ax, kde=False, hist=True, rug=True, norm_hist=False, bins=100)
        else:
            print("Unsupported plot type")
    elif config["quantization"].lower() == "normal":
        if plot_type.lower()=="kde":
            sns.distplot(tensor.detach().numpy(), ax=ax, kde_kws={"color": "r"})
        elif plot_type.lower()=="hist":
            sns.distplot(tensor.detach().numpy(), ax=ax, kde=False, hist=True, rug=True, norm_hist=False, bins=100)
        else:
            print("Unsupported plot type") 
Example #16
Source File: analyze.py    From cryodrgn with GNU General Public License v3.0 6 votes vote down vote up
def analyze_z1(z, outdir, vg):
    '''Plotting and volume generation for 1D z'''
    assert z.shape[1] == 1
    z = z.reshape(-1)
    N = len(z)

    plt.figure(1)
    plt.scatter(np.arange(N), z, alpha=.1, s=2)
    plt.xlabel('particle')
    plt.ylabel('z')
    plt.savefig(f'{outdir}/z.png')

    plt.figure(2)
    sns.distplot(z)
    plt.xlabel('z')
    plt.savefig(f'{outdir}/z_hist.png')

    ztraj = np.linspace(*np.percentile(z,(5,95)), 10) # or np.percentile(z, np.linspace(5,95,10)) ?
    vg.gen_volumes(outdir, ztraj) 
Example #17
Source File: dataframe_explorer.py    From pandasgui with MIT License 6 votes vote down vote up
def update_plot(self):
            plt.ioff()
            col = self.picker.currentText()

            plt.figure()

            arr = self.df[col].dropna()
            if self.df[col].dtype.name in ['object', 'bool', 'category']:
                ax = sns.countplot(y=arr, color='grey', order=arr.value_counts().iloc[:10].index)

            else:
                ax = sns.distplot(arr, color='black', hist_kws=dict(color='grey', alpha=1))

            self.figure_viewer.setFigure(ax.figure)


# Examples 
Example #18
Source File: Auto_NLP.py    From Auto_ViML with Apache License 2.0 6 votes vote down vote up
def draw_dist_plots_summary_cols(df_train, target, summary_cols):
    colors = cycle('byrcmgkbyrcmgkbyrcmgkbyrcmgkbyr')
    target_names = np.unique(df_train[target])
    ncols =2
    nrows = int((len(summary_cols)/2)+0.50)
    fig, axes = plt.subplots(ncols=ncols, nrows=nrows, figsize=(20,nrows*6), dpi=100)
    axs = []
    for i in range(nrows):
        for j in range(ncols):
            axs.append('axes['+str(i)+','+str(j)+']')
    labels = []
    for axi, feature in enumerate(summary_cols):
        for target_name in target_names:
            label = str(target_name)
            color = next(colors)
            sns.distplot(df_train.loc[df_train[target] == target_name][feature],
                         label=label,
                     ax=eval(axs[axi]), color=color, kde_kws={'bw':1.5})
            labels.append(label)
    plt.legend(labels=labels)
    plt.show();
############################################################################# 
Example #19
Source File: question_dialogues.py    From guesswhat with Apache License 2.0 6 votes vote down vote up
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'}) 
Example #20
Source File: word_question.py    From guesswhat with Apache License 2.0 6 votes vote down vote up
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) 
Example #21
Source File: analysis.py    From dl-eeg-review with MIT License 6 votes vote down vote up
def plot_number_channels(df, save_cfg=cfg.saving_config):
    """Plot histogram of number of channels.
    """
    nb_channels_df = ut.split_column_with_multiple_entries(
        df, 'Nb Channels', ref_col='Citation', sep=';\n', lower=False)
    nb_channels_df['Nb Channels'] = nb_channels_df['Nb Channels'].astype(int)
    nb_channels_df = nb_channels_df.loc[nb_channels_df['Nb Channels'] > 0, :]

    fig, ax = plt.subplots(
        figsize=(save_cfg['text_width'] / 2, save_cfg['text_height'] / 4))
    sns.distplot(nb_channels_df['Nb Channels'], kde=False, norm_hist=False, ax=ax)
    ax.set_xlabel('Number of EEG channels')
    ax.set_ylabel('Number of papers')

    logger.info('Stats on number of channels per model: {}'.format(
        nb_channels_df['Nb Channels'].describe()))

    plt.tight_layout()

    if save_cfg is not None:
        fname = os.path.join(save_cfg['savepath'], 'nb_channels')
        fig.savefig(fname + '.' + save_cfg['format'], **save_cfg)

    return ax 
Example #22
Source File: gan.py    From MachineLearning with Apache License 2.0 6 votes vote down vote up
def export_animation(anim_frames):
    i = 0
    for t_data, g_data in anim_frames:
        f, ax = plt.subplots(figsize=(12, 8))
        f.suptitle('Generative Adversarial Network', fontsize=15)
        plt.xlabel('Data values')
        plt.ylabel('Probability density')
        ax.set_xlim(-2, 10)
        ax.set_ylim(0, 1.2)
        sns.distplot(t_data, hist=False, rug=True, color='r', label='Target Data', ax=ax)
        sns.distplot(g_data, hist=False, rug=True, color='g', label='Generated Data', ax=ax)
        f.savefig("images/frame_" + str(i) + ".png")
        print "Frame index: ", i * SAMPLE_RATE
        f.clf()
        plt.close()
        i += 1

# Generate mp4 from images:
# avconv -r 10 -i frame_%d.png -b:v 1000k gan.mp4
# convert -delay 20 -loop 0 output/decision_*.png myimage.gif 
Example #23
Source File: plot_z1.py    From cryodrgn with GNU General Public License v3.0 5 votes vote down vote up
def main(args):
    np.random.seed(args.seed)
    f = args.input
    print(f)
    fi = open(f,'rb')
    x = pickle.load(fi)
    N = len(x)
    plt.scatter(np.arange(N),x, label=f, alpha=args.alpha, s=args.ms)
    #plt.scatter(np.arange(N), x, c=np.arange(len(x[:,0])), label=f, alpha=.1, s=2, cmap='hsv')
    plt.xlim((0,N))
    if args.sample1:
        s = np.random.choice(len(x), args.sample1)
        xd = x[s]
        print(xd)
        plt.plot(s,xd,'o')

    if args.sample2:
        t = np.array_split(np.arange(len(x)),args.sample2)
        t = np.array([np.median(tt,axis=0) for tt in t])
        xsplit = np.array_split(x,args.sample2)
        xd = np.array([np.median(xs,axis=0) for xs in xsplit])
        print(len(xd))
        print(xd)
        plt.plot(t,xd,'o',color='k')
    if args.out_s:
        np.savetxt(args.out_s, xd)
    if args.ylim:
        plt.ylim(args.ylim)
    plt.xlabel('image')
    plt.ylabel('latent encoding')
    plt.legend(loc='best')
    if args.o: 
        plt.savefig(args.o)

    # Plot histogram
    plt.figure()
    sns.distplot(x)
    plt.show() 
Example #24
Source File: utils.py    From generative-graph-transformer with MIT License 5 votes vote down vote up
def plot_histogram_streetmover(x, args):
    r"""
    Plot histogram of streetmover distance, to better analyze the performance of different models
    
    :param x: streetmover distances
    :param args: parsed arguments
    """
    
    sns.set(color_codes=True, style="white")
    
    sns_plot = sns.distplot(x, bins=int(np.max(x) / 0.002), kde=False)  # kde_kws=dict(bw=0.01))
    sns_plot.set_xticks(np.linspace(0, 0.08, 5))
    sns_plot.set_yticks(np.linspace(0, 10000, 6))
    sns_plot.set_xlim(0, 0.09)
    sns_plot.set_ylim(0, 10000)
    plt.grid(which='major', axis='y', color='gray', linestyle='-', linewidth=1, alpha=.5)
    
    mean = np.mean(x)
    median = np.median(x)
    std = np.std(x)
    plt.axvline(mean, 0, 40, ls='--', c='r', label="mean")
    plt.axvline(median, 0, 40, ls='--', c='g', label="median")
    plt.text(0.088, 4000, f"Mean: {str(mean)[:6]}\nMedian: {str(median)[:6]}\nStd: {str(std)[:6]}", fontsize=20,
                       fontdict=dict(horizontalalignment='right'))
    sns_plot.set_ylabel("N datapoints", fontsize=20)
    sns_plot.set_xlabel("StreetMover distance", fontsize=20)
    sns.despine(ax=sns_plot, left=True, bottom=True)
    # sns_plot.set_title(f"Mean: {str(mean)[:6]}\nMedian: {str(median)[:6]}\nStd: {str(std)[:6]}", fontsize=20,
    #                   fontdict=dict(horizontalalignment='right'))
    sns_plot.legend(prop={'size': 20})
    sns_plot.figure.savefig(f"{args.statistics_path}/{args.file_name}.png", bbox_inches='tight') 
Example #25
Source File: utils.py    From mriqc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def plot_dist(
    main_file,
    mask_file,
    xlabel,
    distribution=None,
    xlabel2=None,
    figsize=DINA4_LANDSCAPE,
):
    data = _get_values_inside_a_mask(main_file, mask_file)

    fig = plt.Figure(figsize=figsize)
    FigureCanvas(fig)

    gsp = GridSpec(2, 1)
    ax = fig.add_subplot(gsp[0, 0])
    sns.distplot(data.astype(np.double), kde=False, bins=100, ax=ax)
    ax.set_xlabel(xlabel)

    ax = fig.add_subplot(gsp[1, 0])
    sns.distplot(np.array(distribution).astype(np.double), ax=ax)
    cur_val = np.median(data)
    label = "{0!g}".format(cur_val)
    plot_vline(cur_val, label, ax=ax)
    ax.set_xlabel(xlabel2)

    return fig 
Example #26
Source File: visualize_traindata.py    From Supply-demand-forecasting with MIT License 5 votes vote down vote up
def weather_distribution(self):
        data_dir = g_singletonDataFilePath.getTrainDir()
        self.gapdf = self.load_weatherdf(data_dir)
        print self.gapdf['weather'].describe()
#         sns.distplot(self.gapdf['gap'],kde=False, bins=100);
        
        sns.countplot(x="weather", data=self.gapdf, palette="Greens_d");
        plt.title('Countplot of Weather')
#         self.gapdf['weather'].plot(kind='bar')
#         plt.xlabel('Weather')
#         plt.title('Histogram of Weather')
        return 
Example #27
Source File: brute_force_plotter.py    From brute-force-plotter with MIT License 5 votes vote down vote up
def plot_single_numeric(input_file, col, path):
    df = pd.read_parquet(input_file, columns=[col])
    file_name = os.path.join(path, f"{col}-dist-plot.png")
    data = df[col].dropna()
    f, axes = plt.subplots(2, 1, sharex=True, figsize=(8, 6))
    histogram_violin_plots(data, axes, file_name=file_name)

    # TODO plot log transformation too?
    # file_path = path + col + '-log-dist-plot.png'
    # if not os.path.isfile(file_path):
    # if data.min() < 1:
    # tmp = data + data.min()
    # logged = tmp.map(np.arcsinh)
    # else:
    # logged = data.map(np.log)
    # sns.distplot(logged, axlabel='log distribution of {}'.format(logged.name))
    # plt.tight_layout()
    # plt.savefig(file_path, dpi=120)
    # plt.close()
    #
    # file_path = path + col + '-sqrroot-dist-plot.png'
    # if not os.path.isfile(file_path):
    # square_rooted = data.map(np.sqrt)
    # sns.distplot(square_rooted, axlabel='sqrrot distribution of {}'.format(square_rooted.name))
    # plt.tight_layout()
    # plt.savefig(file_path, dpi=120)
    # plt.close() 
Example #28
Source File: brute_force_plotter.py    From brute-force-plotter with MIT License 5 votes vote down vote up
def histogram_violin_plots(data, axes, file_name=None):
    # histogram
    sns.distplot(data, ax=axes[0], axlabel="")
    sns.violinplot(data, ax=axes[1], inner="quartile", scale="count")
    sns.despine(left=True) 
Example #29
Source File: utils.py    From mriqc with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def plot_fd(fd_file, fd_radius, mean_fd_dist=None, figsize=DINA4_LANDSCAPE):

    fd_power = _calc_fd(fd_file, fd_radius)

    fig = plt.Figure(figsize=figsize)
    FigureCanvas(fig)

    if mean_fd_dist:
        grid = GridSpec(2, 4)
    else:
        grid = GridSpec(1, 2, width_ratios=[3, 1])
        grid.update(hspace=1.0, right=0.95, left=0.1, bottom=0.2)

    ax = fig.add_subplot(grid[0, :-1])
    ax.plot(fd_power)
    ax.set_xlim((0, len(fd_power)))
    ax.set_ylabel("Frame Displacement [mm]")
    ax.set_xlabel("Frame number")
    ylim = ax.get_ylim()

    ax = fig.add_subplot(grid[0, -1])
    sns.distplot(fd_power, vertical=True, ax=ax)
    ax.set_ylim(ylim)

    if mean_fd_dist:
        ax = fig.add_subplot(grid[1, :])
        sns.distplot(mean_fd_dist, ax=ax)
        ax.set_xlabel("Mean Frame Displacement (over all subjects) [mm]")
        mean_fd = fd_power.mean()
        label = r"$\overline{{\text{{FD}}}}$ = {0:g}".format(mean_fd)
        plot_vline(mean_fd, label, ax=ax)

    return fig 
Example #30
Source File: visualize_traindata.py    From Supply-demand-forecasting with MIT License 5 votes vote down vote up
def gapdistricution(self):
        data_dir = g_singletonDataFilePath.getTrainDir()
        self.gapdf = self.load_gapdf(data_dir)
        print self.gapdf['gap'].describe()
#         sns.distplot(self.gapdf['gap'],kde=False, bins=100);
        self.gapdf['gap'].plot(kind='hist', bins=200)
        plt.xlabel('Gaps')
        plt.title('Histogram of Gaps')

        return