当前位置: 首页>>代码示例>>Python>>正文


Python seaborn.countplot方法代码示例

本文整理汇总了Python中seaborn.countplot方法的典型用法代码示例。如果您正苦于以下问题:Python seaborn.countplot方法的具体用法?Python seaborn.countplot怎么用?Python seaborn.countplot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在seaborn的用法示例。


在下文中一共展示了seaborn.countplot方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: plot_model_comparison

# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import countplot [as 别名]
def plot_model_comparison(df, save_cfg=cfg.saving_config):
    """Plot bar graph showing the types of baseline models used.
    """
    fig, ax = plt.subplots(figsize=(save_cfg['text_width'] / 4 * 2, 
                                    save_cfg['text_height'] / 5))
    sns.countplot(y=df['Baseline model type'].dropna(axis=0), ax=ax)
    ax.set_xlabel('Number of papers')
    ax.set_ylabel('')
    plt.tight_layout()

    model_prcts = df['Baseline model type'].value_counts() / df.shape[0] * 100
    logger.info('% of studies that used at least one traditional baseline: {}'.format(
        model_prcts['Traditional pipeline'] + model_prcts['DL & Trad.']))
    logger.info('% of studies that used at least one deep learning baseline: {}'.format(
        model_prcts['DL'] + model_prcts['DL & Trad.']))
    logger.info('% of studies that did not report baseline comparisons: {}'.format(
        model_prcts['None']))

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

    return ax 
开发者ID:hubertjb,项目名称:dl-eeg-review,代码行数:25,代码来源:analysis.py

示例2: plot_country

# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import countplot [as 别名]
def plot_country(df, save_cfg=cfg.saving_config):
    """Plot bar graph showing the country of the first author's affiliation.
    """
    fig, ax = plt.subplots(figsize=(save_cfg['text_width'] / 4 * 3, 
                                    save_cfg['text_height'] / 5))
    sns.countplot(x=df['Country'], ax=ax,
                order=df['Country'].value_counts().index)
    ax.set_ylabel('Number of papers')
    ax.set_xlabel('')
    ax.set_xticklabels(ax.get_xticklabels(), rotation=90)
    plt.tight_layout()

    top3 = df['Country'].value_counts().index[:3]
    logger.info('Top 3 countries of first author affiliation: {}'.format(top3.values))

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

    return ax 
开发者ID:hubertjb,项目名称:dl-eeg-review,代码行数:22,代码来源:analysis.py

示例3: plot_cross_validation

# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import countplot [as 别名]
def plot_cross_validation(df, save_cfg=cfg.saving_config):
    """Plot bar graph of cross validation approaches.
    """
    col = 'Cross validation (clean)'
    df[col] = df[col].fillna('N/M')
    cv_df = ut.split_column_with_multiple_entries(
        df, col, ref_col='Citation', sep=';\n', lower=False)
    
    fig, ax = plt.subplots(
        figsize=(save_cfg['text_width'] / 2, save_cfg['text_height'] / 5))
    sns.countplot(y=cv_df[col], order=cv_df[col].value_counts().index, ax=ax)
    ax.set_xlabel('Number of papers')
    ax.set_ylabel('')
    
    plt.tight_layout()

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

    return ax 
开发者ID:hubertjb,项目名称:dl-eeg-review,代码行数:23,代码来源:analysis.py

示例4: plot_classification_frequency

# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import countplot [as 别名]
def plot_classification_frequency(df, category, file_name, convert_labels = False):
    '''
    Plots the frequency at which labels occur

    INPUT
        df: Pandas DataFrame of the image name and labels
        category: category of labels, from 0 to 4
        file_name: file name of the image
        convert_labels: argument specified for converting to binary classification

    OUTPUT
        Image of plot, showing label frequency
    '''
    if convert_labels == True:
        labels['level'] = change_labels(labels, 'level')

    sns.set(style="whitegrid", color_codes=True)
    sns.countplot(x=category, data=labels)
    plt.title('Retinopathy vs Frequency')
    plt.savefig(file_name) 
开发者ID:llSourcell,项目名称:AI_in_Medicine_Clinical_Imaging_Classification,代码行数:22,代码来源:eda.py

示例5: update_plot

# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import countplot [as 别名]
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 
开发者ID:adamerose,项目名称:pandasgui,代码行数:19,代码来源:dataframe_explorer.py

示例6: plot_chemical_trajectory

# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import countplot [as 别名]
def plot_chemical_trajectory(self, environment, filename):
        """
        Plot the trajectory through chemical space.

        Parameters
        ----------
        environment : str
            the name of the environment for which the chemical space trajectory is desired
        """
        chemical_state_trajectory = self.extract_state_trajectory(environment)

        visited_states = list(set(chemical_state_trajectory))

        state_trajectory = np.zeros(len(chemical_state_trajectory))
        for idx, chemical_state in enumerate(chemical_state_trajectory):
            state_trajectory[idx] = visited_states.index(chemical_state)

        with PdfPages(filename) as pdf:
            sns.set(font_scale=2)
            fig = plt.figure(figsize=(28, 12))
            plt.subplot2grid((1,2), (0,0))
            ax = sns.scatterplot(np.arange(len(state_trajectory)), state_trajectory)
            plt.yticks(np.arange(len(visited_states)), visited_states)

            plt.title("Trajectory through chemical space in {}".format(environment))
            plt.xlabel("iteration")
            plt.ylabel("chemical state")
            plt.tight_layout()

            plt.subplot2grid((1,2), (0,1))
            ax = sns.countplot(y=state_trajectory)

            pdf.savefig(fig)
            plt.close() 
开发者ID:choderalab,项目名称:perses,代码行数:36,代码来源:analysis.py

示例7: plot_type_of_paper

# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import countplot [as 别名]
def plot_type_of_paper(df, save_cfg=cfg.saving_config):
    """Plot bar graph showing the type of each paper (journal, conference, etc.).
    """
    # Move supplements to journal paper category for the plot (a value of one is
    # not visible on a bar graph).
    df_plot = df.copy()
    df_plot.loc[df['Type of paper'] == 'Supplement', :] = 'Journal'

    fig, ax = plt.subplots(figsize=(save_cfg['text_width'] / 4, 
                                    save_cfg['text_height'] / 5))
    sns.countplot(x=df_plot['Type of paper'], ax=ax)
    ax.set_xlabel('')
    ax.set_ylabel('Number of papers')
    ax.set_xticklabels(ax.get_xticklabels(), rotation=90)
    plt.tight_layout()

    counts = df['Type of paper'].value_counts()
    logger.info('Number of journal papers: {}'.format(counts['Journal']))
    logger.info('Number of conference papers: {}'.format(counts['Conference']))
    logger.info('Number of preprints: {}'.format(counts['Preprint']))
    logger.info('Number of papers that were initially published as preprints: '
                '{}'.format(df[df['Type of paper'] != 'Preprint'][
                    'Preprint first'].value_counts()['Yes']))

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

    return ax 
开发者ID:hubertjb,项目名称:dl-eeg-review,代码行数:31,代码来源:analysis.py

示例8: plot_hardware

# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import countplot [as 别名]
def plot_hardware(df, save_cfg=cfg.saving_config):
    """Plot bar graph showing the hardware used in the study.
    """
    col = 'EEG Hardware'
    hardware_df = ut.split_column_with_multiple_entries(
        df, col, ref_col='Citation', sep=',', lower=False)

    # Remove N/Ms because they make it hard to see anything
    hardware_df = hardware_df[hardware_df[col] != 'N/M']
    
    # Add low cost column
    hardware_df['Low-cost'] = False
    low_cost_devices = ['EPOC (Emotiv)', 'OpenBCI (OpenBCI)', 'Muse (InteraXon)', 
                        'Mindwave Mobile (Neurosky)', 'Mindset (NeuroSky)']
    hardware_df.loc[hardware_df[col].isin(low_cost_devices), 
                    'Low-cost'] = True

    fig, ax = plt.subplots(figsize=(save_cfg['text_width'] / 4 * 2, 
                                    save_cfg['text_height'] / 5 * 2))
    sns.countplot(hue=hardware_df['Low-cost'], y=hardware_df[col], ax=ax,
                  order=hardware_df[col].value_counts().index, 
                  dodge=False)
    # sns.catplot(row=hardware_df['low_cost'], y=hardware_df['hardware'])
    ax.set_xlabel('Number of papers')
    ax.set_ylabel('')
    plt.tight_layout()

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

    return ax 
开发者ID:hubertjb,项目名称:dl-eeg-review,代码行数:34,代码来源:analysis.py

示例9: create_distribution

# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import countplot [as 别名]
def create_distribution(dataFile):
    
    return sb.countplot(x='Label', data=dataFile, palette='hls')
    

#by calling below we can see that training, test and valid data seems to be failry evenly distributed between the classes 
开发者ID:nishitpatel01,项目名称:Fake_News_Detection,代码行数:8,代码来源:DataPrep.py

示例10: weather_distribution

# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import countplot [as 别名]
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 
开发者ID:LevinJ,项目名称:Supply-demand-forecasting,代码行数:14,代码来源:visualize_traindata.py

示例11: plot_data

# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import countplot [as 别名]
def plot_data(data):
    # barplot for the depencent variable
    sns.countplot(x='y', data=data, palette='hls')
    plt.show()

    # check the missing values
    print(data.isnull().sum())

    # customer distribution plot
    sns.countplot(y='job', data=data)
    plt.show()

    # customer marital status distribution
    sns.countplot(x='marital', data=data)
    plt.show()

    # barplot for credit in default
    sns.countplot(x='default', data=data)
    plt.show()

    # barptot for housing loan
    sns.countplot(x='housing', data=data)
    plt.show()

    # barplot for personal loan
    sns.countplot(x='loan', data=data)
    plt.show()

    # barplot for previous marketing campaign outcome
    sns.countplot(x='poutcome', data=data)
    plt.show() 
开发者ID:devAmoghS,项目名称:Machine-Learning-with-Python,代码行数:33,代码来源:utils.py

示例12: bar_plot

# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import countplot [as 别名]
def bar_plot(data, col, hue=None, file_name=None):
    sns.countplot(col, hue=hue, data=data.sort_values(col))
    sns.despine(left=True)

    subplots = [
        x for x in plt.gcf().get_children() if isinstance(x, matplotlib.axes.Subplot)
    ]
    for plot in subplots:
        rectangles = [
            x
            for x in plot.get_children()
            if isinstance(x, matplotlib.patches.Rectangle)
        ]
    autolabel(rectangles) 
开发者ID:eyadsibai,项目名称:brute-force-plotter,代码行数:16,代码来源:brute_force_plotter.py

示例13: distribution

# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import countplot [as 别名]
def distribution(self, **kwargs):
        """Plots the label distribution."""
        self._label_times._assert_single_target()
        target_column = self._label_times.target_columns[0]
        dist = self._label_times[target_column]
        is_discrete = self._label_times.is_discrete[target_column]

        if is_discrete:
            ax = sns.countplot(dist, palette=COLOR, **kwargs)
        else:
            ax = sns.distplot(dist, kde=True, color=COLOR[1], **kwargs)

        ax.set_title('Label Distribution')
        ax.set_ylabel('Count')
        return ax 
开发者ID:FeatureLabs,项目名称:compose,代码行数:17,代码来源:plots.py

示例14: cat_count

# 需要导入模块: import seaborn [as 别名]
# 或者: from seaborn import countplot [as 别名]
def cat_count(anns, names, show_count=False, save=False):

    fig, axes = plt.subplots(1, len(anns), sharey=False)

    # Making axes iterable if only single annotation is present
    if len(anns) == 1:
        axes = [axes]

    # Prepare annotations dataframe
    # This should be done at the start
    for ann, name, ax in zip(anns, names, axes):
        ann_df = pd.DataFrame(ann.anns).transpose()
        if 'category_name' in ann_df.columns:
            chart = sns.countplot(data=ann_df,
                                  x='category_name',
                                  order=ann_df['category_name'].value_counts().index,
                                  palette='Set1',
                                  ax=ax)
        else:
            # Add a new column -> category name
            ann_df['category_name'] = ann_df.apply(lambda row: ann.cats[row.category_id]['name'],axis=1)
            chart = sns.countplot(data=ann_df,
                                  x='category_name',
                                  order=ann_df['category_name'].value_counts().index,
                                  palette='Set1',
                                  ax=ax)

        chart.set_title(name)
        chart.set_xticklabels(chart.get_xticklabels(), rotation=90)

        if show_count is True:
            for p in chart.patches:
                height = p.get_height()
                chart.text(p.get_x() + p.get_width() / 2.,
                           height + 0.9,
                           height,
                           ha="center")

    plt.suptitle('Instances per category', fontsize=14, fontweight='bold')
    plt.tight_layout()

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

    out_dir = os.path.join(os.getcwd(), 'results', 'plots')
    if save is True:
        if os.path.exists(out_dir) is False:
            os.mkdir(out_dir)
        plt.savefig(os.path.join(out_dir, "cat_dist" + ".png"),
                    bbox_inches='tight',
                    pad_inches=0,
                    dpi=plt.gcf().dpi)

    plt.show() 
开发者ID:ashnair1,项目名称:COCO-Assistant,代码行数:56,代码来源:coco_stats.py


注:本文中的seaborn.countplot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。