Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Pandas
  • Matplotlib
  • Plotly
  • Altair
  • Bokeh
  • Data Analysis
  • R
  • Machine Learning Math
  • Machin Learning
  • Deep Learning
  • Deep Learning Projects
  • NLP
  • Computer vision
  • Data science
  • Deep learning interview question
  • Machin Learning Interview question
Open In App
Next Article:
Seaborn.barplot() method in Python
Next article icon

Seaborn.barplot() method in Python

Last Updated : 16 Jun, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

Seaborn is a Python data visualization library based on Matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. There is just something extraordinary about a well-designed visualization. The colors stand out, the layers blend nicely together, the contours flow throughout, and the overall package not only has a nice aesthetic quality, but it provides meaningful insights to us as well.

seaborn.barplot() method

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 : seaborn.barplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, estimator=<function mean at 0x000002BC3EB5C4C8>, ci=95, n_boot=1000, units=None, orient=None, color=None, palette=None, saturation=0.75, errcolor='.26', errwidth=None, capsize=None, dodge=True, ax=None, **kwargs,) 
 

Parameters :

Arguments                         Value                                                                              Description
x, y, huenames of variables in ``data`` or vector data, optionalInputs for plotting long-form data. See examples for interpretation.
dataDataFrame, array, or list of arrays, optionalDataset for plotting. If ``x`` and ``y`` are absent, this is interpreted as wide-form. Otherwise it is expected to be long-form.
order, hue_orderlists of strings, optionalOrder to plot the categorical levels in, otherwise the levels are inferred from the data objects.
estimatorcallable that maps vector -> scalar, optionalStatistical function to estimate within each categorical bin.
cifloat or "sd" or None, optionalSize of confidence intervals to draw around estimated values.  If "sd", skip bootstrapping and draw the standard deviation of the observations. If ``None``, no bootstrapping will be performed, and error bars will not be drawn.
n_bootint, optionalNumber of bootstrap iterations to use when computing confidence intervals.
unitsname of variable in ``data`` or vector data, optionalIdentifier of sampling units, which will be used to perform a multilevel bootstrap and account for repeated measures design. 
orient"v" | "h", optionalOrientation of the plot (vertical or horizontal). This is usually inferred from the dtype of the input variables, but can be used to specify when the "categorical" variable is a numeric or when plotting wide-form data.
colormatplotlib color, optionalColor for all of the elements, or seed for a gradient palette.
palettepalette name, list, or dict, optionalColors to use for the different levels of the ``hue`` variable. Should be something that can be interpreted by :func:`color_palette`, or a dictionary mapping hue levels to matplotlib colors.
saturationfloat, optionalProportion of the original saturation to draw colors at. Large patches often look better with slightly desaturated colors, but set this to ``1`` if you want the plot colors to perfectly match the input color spec.
errcolormatplotlib colorColor for the lines that represent the confidence interval.
errwidthfloat, optionalThickness of error bar lines (and caps). 
capsizefloat, optionalWidth of the "caps" on error bars.
dodgebool, optionalWhen hue nesting is used, whether elements should be shifted along the categorical axis. 
axmatplotlib Axes, optionalAxes object to draw the plot onto, otherwise uses the current Axes.
kwargsey, value mappingsOther keyword arguments are passed through to ``plt.bar`` at draw time.

Following steps are used :

  • Import Seaborn
  • Load Dataset from Seaborn as it contain good collection of datasets.
  • Plot Bar graph using seaborn.barplot() method.

Below is the implementation :

Example 1:

Python3
# importing the required library import seaborn as sns import matplotlib.pyplot as plt  # read a titanic.csv file # from seaborn library df = sns.load_dataset('titanic')  # who v/s fare barplot  sns.barplot(x = 'who',             y = 'fare',             data = df)  # Show the plot plt.show() 

Output:

simple barpot

Example 2:

Python3
# importing the required library import seaborn as sns import matplotlib.pyplot as plt  # read a titanic.csv file # from seaborn library df = sns.load_dataset('titanic')   # who v/s fare barplot  sns.barplot(x = 'who',             y = 'fare',             hue = 'class',             data = df)  # Show the plot plt.show() 

Output:

barplot - 2

Example 3:

Python3
# importing the required library import seaborn as sns import matplotlib.pyplot as plt  # read a titanic.csv file # from seaborn library df = sns.load_dataset('titanic')   # who v/s fare barplot  sns.barplot(x = 'who',             y = 'fare',             hue = 'class',             data = df,             palette = "Blues")  # Show the plot plt.show() 

Output:

barplot - 3

Example 4:

Python3
# importing the required library import seaborn as sns import matplotlib.pyplot as plt import numpy as np  # read a titanic.csv file # from seaborn library df = sns.load_dataset('titanic')   # who v/s fare barplot  sns.barplot(x = 'who',             y = 'fare',             hue = 'class',             data = df,             estimator = np.median,             ci = 0)  # Show the plot plt.show() 

Output:


Next Article
Seaborn.barplot() method in Python

D

deepanshu_rustagi
Improve
Article Tags :
  • Data Visualization
  • AI-ML-DS
  • Python-Seaborn
  • AI-ML-DS With Python

Similar Reads

    Barplot using seaborn in Python
    Seaborn is an amazing visualization library for statistical graphics plotting in Python. It provides beautiful default styles and color 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.  Se
    6 min read
    Python seaborn.load_dataset() Method
    Python seaborn.load_dataset() method allows users to quickly load sample datasets provided by Seaborn for practicing and experimenting with data visualization techniques. In this article, we will understand about Python seaborn.load_dataset() method. Python seaborn.load_dataset() Method SyntaxBelow
    2 min read
    seaborn.countplot() in Python
    seaborn.countplot() is a function in the Seaborn library in Python used to display the counts of observations in categorical data. It shows the distribution of a single categorical variable or the relationship between two categorical variables by creating a bar plot. Example:Pythonimport seaborn as
    8 min read
    Boxplot using Seaborn in Python
    Boxplot is used to see the distribution of numerical data and identify key stats like minimum and maximum values, median, identifying outliers, understanding how data is distributed and can compare the distribution of data across different categories or variables. In Seaborn the seaborn.boxplot() fu
    3 min read
    Grouped Barplots in Python with Seaborn
    Prerequisites: Seaborn In this article, we will discuss ways to make grouped barplots using Seaborn in Python. Before that, there are some concepts one must be familiar with: Barcharts: Barcharts are great when you have two variables one is numerical and therefore the other may be a categorical vari
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences