Barplot

A barplot is basically used to aggregate the categorical data according to some methods and by default it’s the mean. It can also be understood as a visualization of the group by action. To use this plot we choose a categorical column for the x-axis and a numerical column for the y-axis, and we see that it creates a plot taking a mean per categorical column.

Syntax:

barplot([x, y, hue, data, order, hue_order, …])

Python3




# import the seaborn library 
import seaborn as sns 
  
# reading the dataset 
df = sns.load_dataset('tips'
  
# change the estimator from mean to
# standard deviation 
sns.barplot(x ='sex', y ='total_bill', data = df,  
            palette ='plasma')


Output:

Explanation:
Looking at the plot we can say that the average total_bill for the male is more than compared to the female.

  • Palette is used to set the color of the plot
  • The estimator is used as a statistical function for estimation within each categorical bin.

Plotting graph using Seaborn | Python

This article will introduce you to graphing in Python with Seaborn, which is the most popular statistical visualization library in Python.

Installation: The easiest way to install seaborn is to use pip. Type following command in terminal:  

pip install seaborn

OR, you can download it from here and install it manually.  

Plotting categorical scatter plots with Seaborn

Similar Reads

Stripplot

Python3 # Python program to illustrate # Plotting categorical scatter  # plots with Seaborn    # importing the required module import matplotlib.pyplot as plt import seaborn as sns    # x axis values x =['sun', 'mon', 'fri', 'sat', 'tue', 'wed', 'thu']    # y axis values y =[5, 6.7, 4, 6, 2, 4.9, 1.8]    # plotting strip plot with seaborn ax = sns.stripplot(x, y);    # giving labels to x-axis and y-axis ax.set(xlabel ='Days', ylabel ='Amount_spend')    # giving title to the plot plt.title('My first graph');    # function to show plot plt.show()...

Swarmplot

...

Barplot

...

Countplot

Python3 # Python program to illustrate # plotting using Swarmplot    # importing the required module import matplotlib.pyplot as plt import seaborn as sns    # use to set style of background of plot sns.set(style="whitegrid")    # loading data-set iris = sns.load_dataset('iris')    # plotting strip plot with seaborn # deciding the attributes of dataset on # which plot should be made ax = sns.swarmplot(x='species', y='sepal_length', data=iris)    # giving title to the plot plt.title('Graph')    # function to show plot plt.show()...

Boxplot

...

Violinplot

...

Stripplot

A barplot is basically used to aggregate the categorical data according to some methods and by default it’s the mean. It can also be understood as a visualization of the group by action. To use this plot we choose a categorical column for the x-axis and a numerical column for the y-axis, and we see that it creates a plot taking a mean per categorical column....