Seaborn plot to visualize Iris data

I have created this Kernel for beginners who want to learn how to plot graphs with seaborn.This kernel is still a work in progress.I will be updating it further when I find some time.If you find my work useful please fo vote by clicking at the top of the page.Thanks for viewing

 [1]:
# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load in 
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
# Input data files are available in the "../input/" directory.
# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory
import os
print(os.listdir("../input"))
# Any results you write to the current directory are saved as output.
['database.sqlite', 'Iris.csv']

Importing pandas and Seaborn module

 [2]:
import pandas as pd
import seaborn as sns

Importing Iris data set

 [3]:
iris=pd.read_csv('../input/Iris.csv')

Displaying data

 [4]:
iris.head()
[4]:
Id SepalLengthCm SepalWidthCm PetalLengthCm PetalWidthCm Species
0 1 5.1 3.5 1.4 0.2 Iris-setosa
1 2 4.9 3.0 1.4 0.2 Iris-setosa
2 3 4.7 3.2 1.3 0.2 Iris-setosa
3 4 4.6 3.1 1.5 0.2 Iris-setosa
4 5 5.0 3.6 1.4 0.2 Iris-setosa
 [5]:
iris.drop('Id',axis=1,inplace=True)

Checking if there are any missing values

 [6]:
iris.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 150 entries, 0 to 149
Data columns (total 5 columns):
SepalLengthCm    150 non-null float64
SepalWidthCm     150 non-null float64
PetalLengthCm    150 non-null float64
PetalWidthCm     150 non-null float64
Species          150 non-null object
dtypes: float64(4), object(1)
memory usage: 5.9+ KB
 [7]:
iris['Species'].value_counts()
[7]:
Iris-versicolor    50
Iris-setosa        50
Iris-virginica     50
Name: Species, dtype: int64

This data set has three varities of Iris plant.

Joint plot

 [8]:
sns.jointplot(x='SepalLengthCm',y='SepalWidthCm',data=iris,size=5)
[8]:
<seaborn.axisgrid.JointGrid at 0x7ff33a187e48>

FacetGrid Plot

 [9]:
import matplotlib.pyplot as plt
%matplotlib inline
sns.FacetGrid(iris,hue='Species',size=5)\
.map(plt.scatter,'SepalLengthCm','SepalWidthCm')\
.add_legend()
[9]:
<seaborn.axisgrid.FacetGrid at 0x7ff30ab847b8>

Boxplot

 [10]:
sns.boxplot(x='Species',y='PetalLengthCm',data=iris)
[10]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff306feaa58>

 

Strip plot

 [11]:
ax=sns.stripplot(x='Species',y='SepalLengthCm',data=iris,jitter=True,edgecolor='gray')

Combining Box and Strip Plots

 [12]:
ax=sns.boxplot(x='Species',y='SepalLengthCm',data=iris)
ax=sns.stripplot(x='Species',y='SepalLengthCm',data=iris,jitter=True,edgecolor='gray')

Violin Plot

 [13]:
sns.violinplot(x='Species',y='SepalLengthCm',data=iris,size=6)
[13]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff306e4ee48>

Pair Plot

 [14]:
sns.pairplot(data=iris,kind='scatter')
[14]:
<seaborn.axisgrid.PairGrid at 0x7ff306e702e8>
 [15]:
sns.pairplot(iris,hue='Species')
[15]:
<seaborn.axisgrid.PairGrid at 0x7ff324e57dd8>

Plotting heat map

 [16]:
plt.figure(figsize=(7,4))
sns.heatmap(iris.corr(),annot=True,cmap='summer')
[16]:
<matplotlib.axes._subplots.AxesSubplot at 0x7ff3043a1400>

Distribution plot

 [17]:
iris.hist(edgecolor='black', linewidth=1.2)
fig=plt.gcf()
fig.set_size_inches(12,6)
plt.show()

Swarm plot

 [18]:
sns.set(style="whitegrid")
fig=plt.gcf()
fig.set_size_inches(10,7)
fig = sns.swarmplot(x="Species", y="PetalLengthCm", data=iris)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s