How to sort countplot in Seaborn

You can sort the countplot in Seaborn with the following code. The given example helps you to understand how to sort countplot in Seaborn. I highly recommend you “Python Crash Course Book” to learn Python.

Example: Sort countplot in Seaborn

# Import the required libraries
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

# Load the Dataset
dataset = sns.load_dataset('diamonds')

# Sort the countplot
sns.countplot(x = 'cut',
              data = dataset,
              order = dataset['cut'].value_counts().index)

# Display the sorted countplot
plt.show()

Output:

Leave a Comment

Your email address will not be published.