Seaborn Final
Seaborn Final
hune
uidsjhfjkhkd
1.Seaborn_Introduction.
#!/usr/bin/env python
# coding: utf-8
# **1.Installing Seaborn**
# In[ ]:
conda install seaborn
# In[ ]:
pip install seaborn
# In[77]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# **4.Create a COUNTPLOT**
# In[78]:
sns.countplot(x='Gender',data=mart)
2.Seaborn_CountPlot
#!/usr/bin/env python
# coding: utf-8
# In[80]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# In[81]:
mart = pd.read_excel("D:/Learnerea/Tables/supermarket_sales.xlsx")
mart.head()
# In[83]:
plt.figure(figsize=(15,5))
sns.countplot(x="Product line",data=mart)
# In[84]:
sns.countplot(y="Product line",data=mart)
# **5.Add hue to get the count on two categories i.e. Product line and
Gender**
# In[86]:
plt.figure(figsize=(15,5))
sns.countplot(x="Product line",hue="Gender",data=mart)
# In[90]:
plt.figure(figsize=(15,5))
sns.countplot(x="Product line",hue="Gender",data=mart,palette='PuBuGn_r')
# In[91]:
plt.figure(figsize=(15,5))
sns.countplot(x='Product line',data=mart
,facecolor = (0,0,0,0)
,linewidth=5
,edgecolor=sns.color_palette('dark',3))
3. Seaborn_BarPlot
#!/usr/bin/env python
# coding: utf-8
# In[106]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# **2. Display the SEBORN dataset names and load one of them for
example**
# In[109]:
# sns.get_dataset_names()
titanic=sns.load_dataset('titanic')
titanic.head()
# In[110]:
mart = pd.read_excel("D:/Learnerea/Tables/supermarket_sales.xlsx")
mart.head()
# In[112]:
plt.figure(figsize=(15,5))
sns.barplot(x='Product line',y='Total',data=mart)
# In[113]:
plt.figure(figsize=(15,5))
sns.barplot(x='Product line',y='Total',hue='Gender',data=mart)
# In[114]:
plt.figure(figsize=(15,5))
sns.barplot(x='Total',y='Product line',data=mart)
# In[120]:
plt.figure(figsize=(15,5))
sns.barplot(x='Product line',y='Total',hue='Gender',data=mart,order=['Electronic_accessories',
'Fashion_accessories','Food_and_beverages', 'Health_and_beauty',
'Home_and_lifestyle','Sports_and_travel']
,hue_order=['Male','Female'])
# In[117]:
x=mart['Product line'].sort_values()
x.unique()
# In[121]:
plt.figure(figsize=(15,5))
sns.barplot(x='Product line',y='Total',hue='Gender',data=mart,order=['Electronic_accessories',
'Fashion_accessories','Food_and_beverages', 'Health_and_beauty',
'Home_and_lifestyle','Sports_and_travel']
,hue_order=['Male','Female']
,capsize=0.2)
# In[122]:
plt.figure(figsize=(15,5))
sns.barplot(x='Product line',y='Total',hue='Gender',data=mart,order=['Electronic_accessories',
'Fashion_accessories','Food_and_beverages', 'Health_and_beauty',
'Home_and_lifestyle','Sports_and_travel']
,hue_order=['Male','Female']
,ci=None)
# **10. Change bar colors using COLOR attribute**
# In[125]:
plt.figure(figsize=(15,5))
sns.barplot(x='Product line',y='Total',data=mart,order=['Electronic_accessories',
'Fashion_accessories','Food_and_beverages', 'Health_and_beauty',
'Home_and_lifestyle','Sports_and_travel']
,hue_order=['Male','Female']
,color='red')
# In[128]:
plt.figure(figsize=(15,5))
sns.barplot(x='Product line',y='Total',hue='Gender',data=mart,order=['Electronic_accessories',
'Fashion_accessories','Food_and_beverages', 'Health_and_beauty',
'Home_and_lifestyle','Sports_and_travel']
,palette='cividis')
plt.figure(figsize=(15,5))
sns.barplot(x='Product line',y='Total',hue='Gender',data=mart,order=['Electronic_accessories',
'Fashion_accessories','Food_and_beverages', 'Health_and_beauty',
'Home_and_lifestyle','Sports_and_travel']
,palette='cividis'
,saturation=0.1)
# In[133]:
plt.figure(figsize=(15,5))
sns.barplot(x='Product line',y='Total',hue='Gender',data=mart,order=['Electronic_accessories',
'Fashion_accessories','Food_and_beverages', 'Health_and_beauty',
'Home_and_lifestyle','Sports_and_travel']
,palette='cividis'
,estimator=np.median)
4.Seaborn_BoxPlot
#!/usr/bin/env python
# coding: utf-8
# In[24]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# In[25]:
mart = pd.read_excel("D:/Learnerea/Tables/supermarket_sales.xlsx")
mart.head()
# In[29]:
sns.boxplot(y='Total',data=mart, width=0.2)
sns.boxplot(x='Payment',y='Total',data=mart)
# In[31]:
sns.boxplot(x='Payment',y='Total',hue='Gender',data=mart)
# **6. Add MEAN marker in the box plot using Showmeans attribute
and change its style using meanprops**
# In[34]:
sns.boxplot(x='Payment',y='Total',hue='Gender',data=mart,showmeans=True,meanprops={"mark
er":"o"
,"markerfacecolor":"white"
,"markersize":"10"
,"markeredgecolor":"black"})
sns.boxplot(x='Total',y='Payment',hue='Gender',data=mart,showmeans=True,meanprops={"mark
er":"o"
,"markerfacecolor":"white"
,"markersize":"5"
,"markeredgecolor":"black"})
# In[41]:
sns.boxplot(x='Total',y='Payment',hue='Gender',data=mart,showmeans=True,meanprops={"mark
er":"o"
,"markerfacecolor":"white"
,"markersize":"5"
,"markeredgecolor":"black"}
,palette='CMRmap'
,linewidth=5)
# In[43]:
plt.figure(figsize=(15,5))
sns.boxplot(data=mart)
5.Seaborn_ViolinPlot
#!/usr/bin/env python
# coding: utf-8
# In[61]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# In[74]:
mart = pd.read_excel("D:/Learnerea/Tables/supermarket_sales.xlsx")
mart.head()
# In[76]:
sns.violinplot(y="Total",data=mart)
# In[79]:
sns.violinplot(x='Payment',y='Total',hue='Gender',data=mart,split=True)
# In[81]:
sns.violinplot(x='Payment',y='Total',hue='Gender',data=mart,split=True,inner='quartile')
# **6. Draw line for each observations in a VIOLINPLOT**
# In[82]:
sns.violinplot(x='Payment',y='Total',hue='Gender',data=mart,split=True,inner='stick')
# In[84]:
sns.violinplot(x='Payment',y='Total',hue='Gender',data=mart,split=True,inner='quartile',bw=.2)
# In[85]:
sns.violinplot(x='Payment',y='Total',hue='Gender',data=mart,split=True,inner='quartile',bw=.2,cu
t=0)
6.Seaborn_StripPlot
#!/usr/bin/env python
# coding: utf-8
# In[61]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# In[74]:
mart = pd.read_excel("D:/Learnerea/Tables/supermarket_sales.xlsx")
mart.head()
sns.stripplot(data=mart, y='Total')
# In[138]:
sns.stripplot(data=mart, y='Total',jitter=0.2)
# In[141]:
sns.stripplot(data=mart, y='Total',linewidth=0.2)
# In[145]:
sns.stripplot(data=mart, y='Total',x='Payment',hue='Gender',jitter=0.2,linewidth=0.5)
# In[146]:
sns.stripplot(data=mart,
y='Total',x='Payment',hue='Gender',jitter=0.2,linewidth=0.5,dodge=True)
# In[157]:
sns.stripplot(data=mart, y='Total',x='Payment',jitter=0.1)
sns.violinplot(data=mart, y='Total',x='Payment',color='gray')
# In[158]:
sns.stripplot(data=mart, y='Total',x='Payment',color="black")
sns.boxplot(
data=mart, y='Total',x='Payment',color='gray')
7.Seaborn_SwarmPlot
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# In[37]:
mart = pd.read_excel(r'D:\Learnerea\Tables\supermarket_sales.xlsx')
mart.head()
# In[38]:
sns.swarmplot(data=mart,y='Total')
# In[40]:
sns.swarmplot(data=mart,y='Total',x='Payment',hue='Gender')
# In[63]:
plt.figure(figsize=(15,5))
sns.swarmplot(data=mart,y='Total',x='Payment',hue='Gender',split=True)
# In[55]:
plt.figure(figsize=(15,5))
sns.swarmplot(data=mart,y='Total',x='Payment',size=10,color='green',edgecolor='black')
# In[57]:
sns.boxplot(data=mart,y='Total',x='Payment')
sns.swarmplot(data=mart,y='Total',x='Payment',color='black')
# In[62]:
sns.violinplot(data=mart,y='Total',x='Payment',inner=None,width=1)
sns.swarmplot(data=mart,y='Total',x='Payment',color='white')
8.Seaborn_CatPlot
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# In[2]:
mart = pd.read_excel("D:/Learnerea/Tables/supermarket_sales.xlsx")
mart.head()
# In[57]:
p=sns.catplot(data=mart,x='Payment',y='Total',col='Gender',kind='box',row='Customer
type',palette='CMRmap_r')
# p.set_titles(col_template="{col_name}")
9.Seaborn_HistPlot
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import statistics as sts
pd.set_option('display.max_rows',None)
# In[2]:
mart = pd.read_excel(r"D:\Learnerea\Tables\supermarket_sales.xlsx")
mart = mart[['Gender','Payment','Unit price','Quantity','Total','gross income']]
mart.head(10)
# In[26]:
sns.histplot(data=mart,y='Total')
# In[29]:
sns.histplot(data=mart,x='Total',binwidth=150)
# In[35]:
plt.figure(figsize=(15,5))
sns.histplot(data=mart,x='Total',bins=np.arange(0,1100,50))
plt.xticks(np.arange(0,1100,50))
# **4. Combine with KDE**
# In[38]:
sns.histplot(data=mart,x='Total',kde=True)
# In[40]:
sns.histplot(data=mart,x='Total',hue='Payment',multiple='stack')
# In[45]:
sns.histplot(data=mart,x='Total',hue='Payment',element='poly')
sns.histplot(data=mart,x='Total',stat='probability')
# In[51]:
sns.histplot(data=mart,x='Total',y='gross income')
10.Seaborn_KDEplot
#!/usr/bin/env python
# coding: utf-8
# In[68]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import statistics as sts
pd.set_option('display.max_rows',None)
# In[69]:
mart = pd.read_excel(r"D:\Learnerea\Tables\supermarket_sales.xlsx")
mart = mart[['Gender','Payment','Unit price','Quantity','Total','gross income']]
mart.head(10)
# In[70]:
sns.kdeplot(data=mart, x='Total')
# In[71]:
sns.kdeplot(data=mart)
# In[74]:
sns.kdeplot(data=mart,x='Total',bw_adjust=0.5)
# In[75]:
sns.kdeplot(data=mart,x='Total',hue='Payment')
# In[76]:
sns.kdeplot(data=mart,x='Total',hue='Payment',multiple='stack')
# **6. Use log scaling to map the variable in KDE**
# In[78]:
sns.kdeplot(data=mart,x='Total',log_scale=True)
# In[84]:
sns.kdeplot(data=mart,x='Total',hue='Payment',multiple='stack',linewidth=5,palette='Dark2',alph
a=0.5)
# In[85]:
# **9. Group the bivariate KDE on a categorical variable and show the
contours**
# In[90]:
11.Seaborn_RugPlot
#!/usr/bin/env python
# coding: utf-8
# In[92]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import statistics as sts
pd.set_option('display.max_rows',None)
# In[93]:
mart = pd.read_excel(r"D:\Learnerea\Tables\supermarket_sales.xlsx")
mart = mart[['Gender','Payment','Unit price','Quantity','Total','gross income']]
mart.head(10)
# In[152]:
plt.figure(figsize=(15,5))
sns.rugplot(data=mart, x='Unit price')
# In[153]:
plt.figure(figsize=(15,5))
sns.rugplot(data=mart, x='Unit price',y='gross income')
plt.figure(figsize=(15,5))
sns.rugplot(data=mart, x='Unit price',y='gross income',hue='Gender')
# In[155]:
plt.figure(figsize=(15,5))
sns.rugplot(data=mart, x='Unit price',y='gross income',hue='Gender',height=0.05)
# In[157]:
plt.figure(figsize=(15,5))
sns.kdeplot(data=mart, x='Unit price',y='gross income',hue='Gender',fill=True)
sns.rugplot(data=mart, x='Unit price',y='gross income',hue='Gender')
# plt.figure(figsize=(15,5))
sns.scatterplot(data=mart, x='Unit price',y='gross income',hue='Gender')
sns.rugplot(data=mart, x='Unit price',y='gross income',hue='Gender')
# In[165]:
plt.figure(figsize=(15,5))
sns.kdeplot(data=mart, x='Unit price',y='gross income',hue='Gender',fill=True)
sns.rugplot(data=mart, x='Unit price',y='gross income',hue='Gender',height=-0.01,clip_on=False)
12.Seaborn_ECDFplot
#!/usr/bin/env python
# coding: utf-8
# In[182]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import statistics as sts
pd.set_option('display.max_rows',None)
# In[212]:
mart = pd.read_excel(r"D:\Learnerea\Tables\supermarket_sales.xlsx")
mart = mart[['Gender','Payment','Unit price','Quantity','Total','gross income']]
mart.head()
# In[219]:
sns.ecdfplot(data=mart,y='gross income',hue='Gender',stat='count')
13.Seaorn_DisPlot
#!/usr/bin/env python
# coding: utf-8
# In[2]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# In[57]:
mart = pd.read_excel(r"D:\Learnerea\Tables\supermarket_sales.xlsx")
mart = mart[['Gender','Payment','Unit price','Quantity','Total','gross income','Branch']]
mart.head()
# In[60]:
sns.displot(data=mart,y='Total',kde=True,rug=True,rug_kws={'height':0.05},hue='Payment',mult
iple='stack',col='Branch',row='Gender')
# In[62]:
sns.displot(data=mart,y='Total',kind='ecdf',hue='Payment',col='Branch',row='Gender')
14.Seaorn_JointPlot
#!/usr/bin/env python
# coding: utf-8
# In[264]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
pd.set_option("display.max_columns",None)
# In[265]:
iris = sns.load_dataset('iris')
iris.head()
# In[266]:
sns.jointplot(data=iris,x='sepal_length',y='petal_length')
# In[272]:
sns.jointplot(data=iris,x='sepal_length',y='petal_length'
,kind='resid')
# In[274]:
sns.jointplot(data=iris,x='sepal_length',y='petal_length'
,hue='species')
# In[285]:
sns.jointplot(data=iris,x='sepal_length',y='petal_length'
# ,color='red'
# ,hue='species'
# ,palette='BuPu'
,joint_kws=dict(marker='+'
,color='red')
,marginal_kws=dict(color='green',kde=True))
sns.jointplot(data=iris,x='sepal_length',y='petal_length'
,height=5
,ratio=3
# ,space=5
,marginal_ticks=True)
# In[308]:
l=sns.jointplot(data=iris,x='sepal_length',y='petal_length',joint_kws=dict(color='red'))
l.plot_joint(sns.kdeplot)
l.plot_joint(sns.rugplot,height=0.1,color='red')
15.Seaorn_PairPlot
#!/usr/bin/env python
# coding: utf-8
# In[9]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# In[65]:
iris = sns.load_dataset('iris')
# iris = iris[['species','sepal_length','petal_length']]
iris.head()
# **1. Creating a basic PAIR PLOT**
# In[66]:
sns.pairplot(data=iris)
# In[67]:
sns.pairplot(data=iris,diag_kind='kde')
# **3. Changing the non diagonal plot KIND to scatter, kde, hist or
reg**
# In[68]:
sns.pairplot(data=iris,kind="reg")
# **4. Adding hue to the PAIR PLOT**
# In[69]:
sns.pairplot(data=iris,hue='species')
# In[72]:
sns.pairplot(data=iris,x_vars=['sepal_width','petal_width','petal_length'],y_vars=['sepal_length','s
epal_width'],diag_kind=None)
# In[74]:
sns.pairplot(data=iris,corner=True)
sns.pairplot(data=iris,diag_kws=dict(color='green',kde=True)
,plot_kws=dict(color='red',marker=10,s=100))
# **8. Creating KDE plot on top of the PAIR PLOT using map_lower or
upper**
# In[87]:
l=sns.pairplot(data=iris,plot_kws=dict(color='red'))
l.map_upper(sns.kdeplot)
l.map_lower(sns.kdeplot)
16.Seaborn_ScatterPlot
#!/usr/bin/env python
# coding: utf-8
# In[195]:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# In[239]:
mart = pd.read_csv(r'D:\Learnerea\Tables\train.csv').sample(50)
mart[['Tier']]=mart['Outlet_Location_Type'].str.split(expand=True)[1]
mart.to_excel(r'D:\Learnerea\Tables\mart_train_sample.xlsx',index=False)
# In[216]:
sns.scatterplot(data=mart,x='Item_MRP',y='Sales')
sns.scatterplot(data=mart,x='Item_MRP',y='Sales',hue='Outlet_Size')
# In[219]:
sns.scatterplot(data=mart,x='Item_MRP',y='Sales',style='Outlet_Size'
,markers={"High":"^","Small":"v","Medium":"o"})
# In[237]:
sns.scatterplot(data=mart,x='Item_MRP',y='Sales',style='Outlet_Size'
,hue='Outlet_Size'
,s=200
,markers={"High":"^","Small":"v","Medium":"o"})
# **5. Grouping basis on numeric variable using HUE and use
PALETTE**
# In[226]:
sns.scatterplot(data=mart,x='Item_MRP',y='Sales'
# ,style='Outlet_Size'
,hue='Outlet_Size'
,palette='Purples_r'
,markers={"High":"^","Small":"v","Medium":"o"})
# In[231]:
sns.scatterplot(data=mart,x='Item_MRP',y='Sales'
,hue='Outlet_Size'
,size='Tier'
,sizes=(20,200)
,legend='full'
,palette='Purples_r'
,markers={"High":"^","Small":"v","Medium":"o"})
# **7. Change the Marker size with S arguement**
# In[236]:
sns.scatterplot(data=mart,x='Item_MRP',y='Sales',s=500,color='red',edgecolor='black')
17.Seaborn_LinePlot
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# In[4]:
mart = pd.read_csv(r'D:\Learnerea\Tables\train.csv')
mart[['Tier']]=mart['Outlet_Location_Type'].str.split(expand=True)[1]
mart.head()
# In[336]:
#---Estimator = None"
# height = [5, 5, 7, 5, 8]
# age = [22,42,30,35,40]
# sns.lineplot(x=age,y=height,estimator=None)
#---Estimator = sum
height = [5, 6, 7, 6.5,4]
age = [22,25,30,25,25]
sns.lineplot(x=age,y=height,estimator=sum)
# In[334]:
sns.lineplot(data=mart,x="Outlet_Year",y="Sales",ci=None,estimator=None)
# In[342]:
sns.lineplot(data=mart,x="Outlet_Year",y="Sales",n_boot=2)
# In[347]:
sns.lineplot(data=mart,x="Outlet_Year",y="Sales",ci=None
,hue='Outlet_Size'
,palette=['red','green','blue'])
# In[350]:
sns.lineplot(data=mart,x="Outlet_Year",y="Sales",ci=None
,style='Outlet_Size'
,markers=True
,dashes=False)
# In[353]:
sns.lineplot(data=mart,x="Outlet_Year",y="Sales",ci=None
,size='Outlet_Size'
,sizes=(.5,5))
# In[360]:
sns.lineplot(data=mart,x="Outlet_Year",y="Sales",ci=None
,hue='Outlet_Size'
# ,style='Outlet_Size'
# ,markers=True
,size='Tier'
)
18.Seaborn_RelPlot
#!/usr/bin/env python
# coding: utf-8
# In[60]:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# In[61]:
mart = pd.read_excel(r'D:\Learnerea\Tables\mart_linePlot.xlsx').sample(n=50)
mart.columns=mart.columns.str.lower()
mart.head()
# In[76]:
mart.to_excel(r'D:\Learnerea\Tables\mart_relPlot.xlsx',index=False)
# In[75]:
sns.relplot(data=mart,x='outlet_year',y='sales',s=100,hue='outlet_size'
# ,col='outlet_size'
# ,row='tier'
# ,hue='outlet_size'
,palette=['green','red','yellow'])
19.Seaborn_RegPlot
#!/usr/bin/env python
# coding: utf-8
# In[2]:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# In[3]:
tips = sns.load_dataset('tips')
tips.head()
# In[23]:
sns.regplot(data=tips,x='total_bill',y='tip')
# **2. Change the styling of reg plot, only line, only scatter, show/hide
the ci, change the ci value, change n_boot**
# In[38]:
sns.regplot(data=tips,x='total_bill',y='tip'
# ,color='red'
# ,marker='+'
,line_kws=dict(color='red',linestyle='--')
,scatter_kws=dict(s=100,color='green',alpha=0.5)
,ci=60
,n_boot=500)
# In[39]:
sns.regplot(data=tips,x='total_bill',y='tip')
20.Seaborn_HeatMap
#!/usr/bin/env python
# coding: utf-8
# In[58]:
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
# In[12]:
mart = pd.read_excel(r'D:\Learnerea\Tables\mart_linePlot.xlsx')
mart.columns = mart.columns.str.lower()
mart.head(10)
# In[61]:
martPiv = mart.pivot_table(index='outlet_year',columns='outlet_size',values='sales')
martPiv
# In[66]:
sns.set_style('white')
plt.figure(figsize=(5,5))
sns.heatmap(martPiv
# ,square=True
,annot=True
,fmt='.0f'
,annot_kws=dict(size=15,weight='bold')
,linewidths=0.5
,linecolor='black'
,cmap='OrRd_r')
# In[68]:
sns.heatmap(mart.corr()
,vmin=-1
,vmax=1
,center=0
,cmap='OrRd_r'
,annot=True
,fmt='.1f'
,annot_kws=dict(size=15,weight='bold')
,linecolor='black'
,linewidths=0.5)
21.Seaborn_ClusterMap
#!/usr/bin/env python
# coding: utf-8
# In[45]:
import pandas as pd
import matplotlib.pyplot as plt
# import numpy as np
import seaborn as sns
# from sunbird.categorical_encoding import frequency_encoding
pd.set_option('display.max_rows',None)
# In[87]:
mart = pd.read_excel(r'D:\Learnerea\Tables\mart_linePlot.xlsx')
mart.columns = mart.columns.str.lower()
mart.head(10)
# In[88]:
martPiv=mart.pivot_table(index='outlet_year',columns='outlet_size',values='sales')
martPiv.head()
# In[111]:
sns.clustermap(martPiv
# ,col_cluster=False
,row_cluster=False
,annot=True
,fmt='.0f'
# ,z_score=1
,standard_scale=1
,linewidth=.5
)
22.Seaborn_FacetGrid
#!/usr/bin/env python
# coding: utf-8
# In[95]:
import pandas as pd
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
# In[135]:
mart = pd.read_excel(r'D:\Learnerea\Tables\mart_linePlot.xlsx')
mart.columns = mart.columns.str.lower()
mart.head()
# In[125]:
mart.outlet_size.unique()
# In[136]:
mart.outlet_location_type.unique()
# In[142]:
learnerea=sns.FacetGrid(mart,col='outlet_size')
learnerea.map_dataframe(sns.scatterplot,x='outlet_year',y='sales',hue='outlet_location_type'
,marker='+'
,alpha=0.5
,color='red'
,s=100)
# In[152]:
learnerea=sns.FacetGrid(mart,col='outlet_size',row='outlet_location_type',sharey=False,ylim=(0,
1000))
learnerea.map_dataframe(sns.histplot,x='sales')
learnerea.set_axis_labels('sales','count')
learnerea.set_titles(col_template='{col_name} Size',row_template='{row_name} Type')