Saturday, July 4, 2026
HomeLanguagesHow to overlap two Barplots in Seaborn?

How to overlap two Barplots in Seaborn?

Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides beautiful default styles and colour palettes to make statistical plots more attractive. It is built on the top of matplotlib library and also closely integrated to the data structures from pandas.

Bar Plot is used to represent categories of data using rectangular bars. We can overlap two barplots in seaborn by creating subplots.

Steps required to overlap two barplots in seaborn:

  1. Importing seaborn and matplotlib library,  seaborn for plotting graph and matplotlib for using subplot().
  2. Creating dataframe.
  3. Creating two subplots on the same axes.
  4. Displaying the plot.

Below are some examples based on the above approach:

Example 1:

Python3




# importing all required libraries
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
 
# creating dataframe
df = pd.DataFrame({
    'X': [1, 2, 3],
    'Y': [3, 4, 5],
    'Z': [2, 1, 2]
})
 
# creating subplots
ax = plt.subplots()
 
# plotting columns
ax = sns.barplot(x=df["X"], y=df["Y"], color='b')
ax = sns.barplot(x=df["X"], y=df["Z"], color='r')
 
# renaming the axes
ax.set(xlabel="x-axis", ylabel="y-axis")
 
# visualizing illustration
plt.show()


Output:

Example 2:

Python3




#importing all required libraries
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
 
#creating dataframe
df=pd.DataFrame({
    'X':[i for i in range(10,110,10)],
    'Y':[i for i in range(100,0,-10)],
    'Z':[i for i in range(10,110,10)]
})
 
#creating subplots
ax=plt.subplots()
 
#plotting columns
ax=sns.barplot(x=df["X"],y=df["Y"],color = 'lime')
ax=sns.barplot(x=df["X"],y=df["Z"],color = 'green')
 
#renaming the axes
ax.set(xlabel="x-axis", ylabel="y-axis")
 
# visualizing illustration
plt.show()


 

 

Output:

 

 

RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32519 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6900 POSTS0 COMMENTS
Nicole Veronica
12015 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12110 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6967 POSTS0 COMMENTS