Python - Seaborn

 

SEABORN

  1. Bar Plot

  2. Count Plot

  3. Box Plot

  4. Swarm Plot

  5. Joint Plot

  6. Point Plot

  7. Lm Plot

  8. Kde Plot

  9. Violin Plot

Birinci Titanic Datasetini daxil edib onun haqqinda biraz melumat elde edeceyik

import seaborn as sns

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

#Datasetimizi getiririk

df = sns.load_dataset("titanic")
df.head(10)

   survived  pclass     sex   age  sibsp  parch     fare embarked   class  \
0         0       3    male  22.0      1      0   7.2500        S   Third  
1         1       1  female  38.0      1      0  71.2833        C   First  
2         1       3  female  26.0      0      0   7.9250        S   Third  
3         1       1  female  35.0      1      0  53.1000        S   First  
4         0       3    male  35.0      0      0   8.0500        S   Third  
5         0       3    male   NaN      0      0   8.4583        Q   Third  
6         0       1    male  54.0      0      0  51.8625        S   First  
7         0       3    male   2.0      3      1  21.0750        S   Third  
8         1       3  female  27.0      0      2  11.1333        S   Third  
9         1       2  female  14.0      1      0  30.0708        C  Second  

    who  adult_male deck  embark_town alive  alone 
0    man        True  NaN  Southampton    no  False 
1  woman       False    C    Cherbourg   yes  False 
2  woman       False  NaN  Southampton   yes   True 
3  woman       False    C  Southampton   yes  False 
4    man        True  NaN  Southampton    no   True 
5    man        True  NaN   Queenstown    no   True 
6    man        True    E  Southampton    no   True 
7  child       False  NaN  Southampton    no  False 
8  woman       False  NaN  Southampton   yes  False 
9  child       False  NaN    Cherbourg   yes  False  

Bar Plot

sns.barplot(x = 'who', y = 'fare',hue = 'class',  data = df, palette = 'viridis')

<AxesSubplot:xlabel='who', ylabel='fare'>

#Rengleri deyisdire bilerik burda


sns.barplot(x = "class", y = "fare",hue = "who" data = df, palette = "flare")

Count Plot

sns.countplot(x = 'who',hue = 'survived', data = df, palette = 'flare')

<AxesSubplot:xlabel='who', ylabel='count'>

#Burda Bardan ferqli olaraq say veririk. Yeni ki hansi sinifden nece denedi.

sns.countplot(x = "class", data = df)

#Burda yan da cevire bilerik

sns.countplot(y = 'class', data = df)

#Yene men birden cox parametr vermek istesem?

sns.countplot(x = "class",hue = "who", data = df)

#Palette deyisdire bilerik yene

sns.countplot(x = "class",hue = "who", data = df, palette = "flare")

Box Plot

sns.boxplot(x = 'fare',y = 'class', data = df)

<AxesSubplot:xlabel='fare', ylabel='class'>

#Boxplot yazilma qaydasi
plt.figure(figsize = (10,15))
sns.boxplot(y = "fare", data = df2)

#Bes tekce x axisine gore vere bilirik? Ayira bilerik!

sns.boxplot(x = "class", y = "fare", data = df)

Swarm Plot

#Normalda bu chart cox gec isleyir. Istifade etmemeyiniz meslehetdir
plt.figure(figsize = (14,7))
sns.swarmplot(x="fare", data = df)

C:\Users\Tunjay Majnunlu\anaconda3\lib\site-packages\seaborn\categorical.py:1296: UserWarning: 36.6% of the points cannot be placed; you may want to decrease the size of the markers or use stripplot.
  warnings.warn(msg, UserWarning)

<AxesSubplot:xlabel='fare'>

#Cinsiyyete gore yarada bilerik

sns.swarmplot(x = "who", y = "fare", data = df)

Joint Plot

sns.jointplot(x = 'fare', y = 'age', data = df, kind = 'hex')

<seaborn.axisgrid.JointGrid at 0x1e1b3d02c10>

#Burda 2 eded reqemli sutun arasindaki melumatlari inceleye bilerik

sns.jointplot(x = "age", y = "fare", data = df, kind = "hex")

#Burda hex-le limitli deyilik, basqa novler de vere bilerik

sns.jointplot(x = "age", y = "fare", data = df, kind = "scatter")

Point Plot

#Melumatlari siniflendirir ve ortalama ve ortalamadan yayinmani verir

sns.pointplot(x = "who", y = "fare", data = df)

<AxesSubplot:xlabel='who', ylabel='fare'>

#Gelin reqemle baxaq

df.groupby("who")["fare"].mean()

#Elave bir deyisken qoya bilerik

sns.pointplot(x = "who", y = "fare",hue = "class", data = df)

Violin Plot

#Reqemle olan melumatlari tehlil etmek ucun istifade olunur

sns.violinplot(x = "fare", data = df)

<AxesSubplot:xlabel='fare'>

#Siniflere gore ferqlendire de bilerik bu qrafiki

sns.violinplot(x = "class", y = "fare", data = df)

<AxesSubplot:xlabel='class', ylabel='fare'>

#2 deyiskene gore de ferqlendire bilerik

sns.violinplot(x = "class", y = "fare", hue = "who", data = df)

KDE Plot

sns.kdeplot(x = 'fare', data = df)

<AxesSubplot:xlabel='fare', ylabel='Density'>

LM Plot

sns.lmplot(x = 'age', y = 'fare', data = df)

<seaborn.axisgrid.FacetGrid at 0x1e1b4069a00>

plt.figure(figsize = (15,7))
sns.lineplot(x = 'age', y = 'fare',hue = 'class', data = df)

<AxesSubplot:xlabel='age', ylabel='fare'>


Popular posts from this blog

Power BI DAX Functions

Python - Pandas

Power BI - Lifehacks