
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Bar Plot in Seaborn Library for Python
Seaborn is a library that helps in visualizing data. It comes with customized themes and a high level interface.
In previous plots, we plotted the entire dataset on the graph. With the help of bar plots, we can understand the central tendency of the distribution of data.
The barplot function establishes the relationship between a categorical variable and a continuous variable. Data is represented in the form of rectangular bars where the length of the bar indicates the proportion of data in that specific category.
Let us understand bar plots with the help of ‘titanic’ dataset −
Example
import pandas as pd import seaborn as sb from matplotlib import pyplot as plt my_df = sb.load_dataset('titanic') sb.barplot(x = "sex", y = "survived", hue = "class", data = my_df) plt.show()
Output
Explanation
- The required packages are imported.
- The input data is ‘titanic’ which is loaded from the seaborn library.
- This data is stored in a dataframe.
- The ‘load_dataset’ function is used to load the iris data.
- This data is visualized using the ‘barplot’ function.
- Here, the dataframe is supplied as parameter.
- Also, the x and y values are specified.
- This data is displayed on the console.
Advertisements