Drawing A Bar Plot Using Seaborn


  • A bar plot or a bar chart or a bar graph is drawn by drawing vertical or horizontal bars of various lengths in proportion to the data values belonging to several categories. For e.g., GDP of a country during each month of the year can be drawn in a bar chart with each bar representing the GDP from each month.
  • The barplot() function from the seaborn visualization library draws a bar plot. It internally makes use of bar(), barh() functions from the matplotlib library.
  • The barplot() function from seaborn makes few things even more simpler. The function automatically calculates the mean value of the data(i.e., the default point estimate) when multiple data points are present for a category and displays the bar height to this point estimate.
  • Seaborn also draws the dispersion of the data, based on the value passed to the parameter "ci"(i.e, denoting the confidence interval). If "sd" is passed as the value to this parameter the error bars will denote the standard deviation.


# Example Python program that draws a bar plot
# using the seaborn
import seaborn as sbn
import matplotlib.pyplot as plt
import pandas as pds
import numpy as np

# Players and their trial data
players = ["Player1", "Player2", "Player3",
           "Player1", "Player2", "Player3",
           "Player1", "Player2", "Player3"];

jumps = [6.3, 5.9, 6.6,
         6.2, 6.0, 6.7,
         6.5, 6.4, 6.8];

playdata = {"Player":players,

#  Create a pandas dataframe
df = pds.DataFrame(data = playdata);

# Create a bar plot
sbn.barplot(x="Player", y="Distance", data=df);


A bar plot drawn using the Python visualization library - seaborn

Copyright 2020 © pythontic.com