How to plot BoxPlot in Seaborn

You can easily plot a boxplot in Seaborn with the following code. The given examples with solutions will help you to understand how to plot a boxplot in Seaborn. I highly recommend the “Python Crash Course Book” to learn Python.

Example 1: Boxplot of two columns in Seaborn

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

# Load the Dataset
df = sns.load_dataset("iris")

# Draw Box Plot
sns.boxplot(x="species", y="petal_width", data=dataset)

# Display the plot
plt.show()

Output:

Example 2: Boxplot of a single column

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

# Load the Dataset
df = sns.load_dataset("iris")

# Draw Box Plot
sns.boxplot(x=df["sepal_length"], data=dataset)

# Display the plot
plt.show()

Output:

Leave a Comment

Your email address will not be published.