How to change color of bars in Seaborn

You can change the color of bars in Seaborn with the following code. The given examples help you to understand how to change the color of bars. I highly recommend you “Python Crash Course Book” to learn Python.

Example 1: “cool” color of bars

If you want to change the color of bars then use the parameter palette. There are many colors available for this parameter.

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

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

# Draw Horizontal Bar Graph
sns.barplot(x="species", y="sepal_width", data=dataset, palette="cool")

# Display the plot
plt.show()

Output:

Example 2: “Greens” color of bars in Seaborn

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

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

# Draw Horizontal Bar Graph
sns.barplot(x="species", y="sepal_width", data=dataset, palette="Greens")

# Display the plot
plt.show()

Output:

Leave a Comment

Your email address will not be published.