Data Visualization using Bar Plot (Seaborn Library)

Home » News » Data Visualization using Bar Plot (Seaborn Library)
Lets visualize our data with Bar Plot which is present in Seaborn library. 


We can pass various parameters to barplot like hue, confidence interval (ci), capsize, estimator (mean, median etc.), order, palette, color, saturation etc. 


Lets explore Bar Plot using Tips dataset.

Step 1: Import required libraries

import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline

Step 2: Load Tips dataset

tips=sns.load_dataset(‘tips')
tips.head()

Step 3: Explore data using Bar Plot

sns.barplot(x='day', y='total_bill', data=tips)


Horizontal Bar Plot


sns.barplot(x='total_bill', y='day', data=tips)


Set color and saturation level

sns.barplot(x='day', y='total_bill', data=tips, color='green') 

sns.barplot(x='day', y='total_bill', data=tips, color='green', saturation=0.3)  


By default, estimator is mean, you can also set it to median or anything else


sns.barplot(x='day', y='total_bill', data=tips, estimator=np.median)


Add hue parameter

sns.barplot(x='day', y='total_bill', data=tips, hue='sex')

sns.barplot(x='day', y='total_bill', data=tips, hue='sex', palette='autumn')

sns.barplot(x='day', y='total_bill', data=tips, hue='sex', color='green')

sns.barplot(x='day', y='total_bill', data=tips, hue='sex', palette='spring', order=[‘Sat', ‘Sun', ‘Thur', ‘Fri'])

sns.barplot(x='sex', y='total_bill', data=tips, hue='sex', palette='spring', order=[‘Male', ‘Female'])


Add confidence interval and capsize parameter

Black lines in bar plot represent error parts. We can set the capsize and confidence interval (ci) of the error parts. A confidence interval is a range of values, derived from sample statistics, that is likely to contain the value of an unknown population parameter.

sns.barplot(x='day', y='total_bill', data=tips, ci=99)
sns.barplot(x='day', y='total_bill', data=tips, ci=34)


sns.barplot(x='day', y='total_bill', data=tips, capsize=0.3)


You can download my Jupyter notebook from here. I recommend to also try above code with Iris dataset.

Leave a Reply

Your email address will not be published. Required fields are marked *

New Providers
Quotex

1000+ Trading Instruments
The best trading broker in the world.

Stockity

1000+ Trading Instruments
The best trading broker in the world.

New Games
Lies of P

$59.99 Standard Edition
28% Save Discounts
See Top 10 Provider Games

COCOON

$24.99 Standard Edition
28% Save Discounts
See Top 10 Provider Games

New Offers
Commission up to $1850 for active user of affiliate program By Exness

Top Points © Copyright 2023 | By Topoin.com Media LLC.
Topoin.info is a site for reviewing the best and most trusted products, bonus, offers, business service providers and companies of all time.

Discover more from Topoin

Subscribe now to keep reading and get access to the full archive.

Continue reading