- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to limit the number of groups shown in a Seaborn countplot using Matplotlib?
To limit the number of groups shown in a Seaborn countplot, we can use a variable group_count, used in countplot() method arguments.
Steps
Create a figure and two sets of subplots.
Create a data frame using Pandas, with two keys.
Initalize a variable group_count to limit the group count in countplot() method.
Use countplot() method to show the counts of observations in each categorical bin using bars.
Adjust the padding between and around the subplots.
Example
import pandas as pd import numpy as np import seaborn as sns from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True f, axes = plt.subplots(1, 2) df = pd.DataFrame(dict(col1=np.linspace(1, 10, 5), col2=np.linspace(1, 10, 5), col3=np.linspace(1, 10, 5))) group_count = 1 sns.countplot(df.col1, x='col1', color="red", ax=axes[0], order=df.col1.value_counts().iloc[:group_count].index) sns.countplot(df.col2, x="col2", color="green", ax=axes[1], order=df.col2.value_counts().iloc[:group_count].index) plt.tight_layout() plt.show()
Output
- Related Articles
- How do I plot two countplot graphs side by side in Seaborn using Matplotlib?
- How can the countplot be used to visualize data in Python Seaborn Library?
- Matplotlib – How to show the count values on the top of a bar in a countplot?
- How to change the figuresize using Seaborn factorplot in Matplotlib?
- How to customize the axis label in a Seaborn jointplot using Matplotlib?
- How to make a heatmap square in Seaborn FacetGrid using Matplotlib?
- How to set the range of Y-axis for a Seaborn boxplot using Matplotlib?
- How to plot multiple Seaborn Jointplot in Subplot using Matplotlib?
- How to adjust transparency (alpha) in Seaborn pairplot using Matplotlib?
- How to add percentages on top of bars in Seaborn using Matplotlib?
- How to increase the font size of the legend in my Seaborn plot using Matplotlib?
- How to move the legend to outside of a Seaborn scatterplot in Matplotlib?
- How to add a legend on Seaborn facetgrid bar plot using Matplotlib?
- How to create a stacked bar chart for my DataFrame using Seaborn in Matplotlib?
- How to turn off error bars in Seaborn Bar Plot using Matplotlib?

Advertisements