Introduction to Data Visualization with SeaBorn

Mohomed Ashkar Haris
4 min readNov 25, 2020
seaborn

Seaborn is a python data visualization library based on Matplotlib. We can draw attractive and informative statistical graphs with high level interface using SeaBorn. We know that, we need a visualization technique to get a good understanding on our data set. SeaBorn is built to provide high level visualization for our datasets.

We can choose several themes with different color patterns to make our data set more informative. This is highly integrated with PyData. However,in this article we only see basic operations in seaborn. Let’s see what those operations are.

Import

import numpy as np
import scipy as sp
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sb

Import Dataset from Github

database=sb.load_dataset('diamonds')
print(database)
carat cut color clarity depth table price x y z
0 0.23 Ideal E SI2 61.5 55.0 326 3.95 3.98 2.43
1 0.21 Premium E SI1 59.8 61.0 326 3.89 3.84 2.31
2 0.23 Good E VS1 56.9 65.0 327 4.05 4.07 2.31
3 0.29 Premium I VS2 62.4 58.0 334 4.20 4.23 2.63
4 0.31 Good J SI2 63.3 58.0 335 4.34 4.35 2.75
... ... ... ... ... ... ... ... ... ... ...
53935 0.72 Ideal D SI1 60.8 57.0 2757 5.75 5.76 3.50
53936 0.72 Good D SI1 63.1 55.0 2757 5.69 5.75 3.61
53937 0.70 Very Good D SI1 62.8 60.0 2757 5.66 5.68 3.56
53938 0.86 Premium H SI2 61.0 58.0 2757 6.15 6.12 3.74
53939 0.75 Ideal D SI2 62.2 55.0 2757 5.83 5.87 3.64

[53940 rows x 10 columns]

DistPlot

sb.distplot(database['carat'])
plt.ylabel('Density')
plt.show()
png

Change Dataset

database=sb.load_dataset('tips')
print(database)
total_bill tip sex smoker day time size
0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3
2 21.01 3.50 Male No Sun Dinner 3
3 23.68 3.31 Male No Sun Dinner 2
4 24.59 3.61 Female No Sun Dinner 4
.. ... ... ... ... ... ... ...
239 29.03 5.92 Male No Sat Dinner 3
240 27.18 2.00 Female Yes Sat Dinner 2
241 22.67 2.00 Male Yes Sat Dinner 2
242 17.82 1.75 Male No Sat Dinner 2
243 18.78 3.00 Female No Thur Dinner 2

[244 rows x 7 columns]

Joint Plot

sb.jointplot(x='total_bill',y='tip',data=database)
plt.show()
png

Change Dataset

database=sb.load_dataset('flights')
print(database)
year month passengers
0 1949 January 112
1 1949 February 118
2 1949 March 132
3 1949 April 129
4 1949 May 121
.. ... ... ...
139 1960 August 606
140 1960 September 508
141 1960 October 461
142 1960 November 390
143 1960 December 432

[144 rows x 3 columns]

Cat Plot

sb.catplot(x='year',y='passengers',data=database)
plt.show()
png

Cat Plot : Violin

sb.catplot(x='year',y='passengers',data=database,kind='violin')
plt.show()
png

Cat Plot : Box

sb.catplot(x='year',y='passengers',data=database,kind='box')
plt.show()
png

Change Dataset

database=sb.load_dataset('tips')
print(database)
total_bill tip sex smoker day time size
0 16.99 1.01 Female No Sun Dinner 2
1 10.34 1.66 Male No Sun Dinner 3
2 21.01 3.50 Male No Sun Dinner 3
3 23.68 3.31 Male No Sun Dinner 2
4 24.59 3.61 Female No Sun Dinner 4
.. ... ... ... ... ... ... ...
239 29.03 5.92 Male No Sat Dinner 3
240 27.18 2.00 Female Yes Sat Dinner 2
241 22.67 2.00 Male Yes Sat Dinner 2
242 17.82 1.75 Male No Sat Dinner 2
243 18.78 3.00 Female No Thur Dinner 2

[244 rows x 7 columns]
graph=sb.FacetGrid(database,col='sex',hue='smoker')
graph.map(plt.scatter,'total_bill','tip')
plt.show()
png

Please refer documentation for more details.

--

--