In [3]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
In [4]:
import seaborn as sns
In [6]:
tips=sns.load_dataset('tips')
In [7]:
sns.lineplot(x='size',y='tip',data=tips,hue='time', style='time',palette=['red','blue'],markers=['o','^'])
plt.title('Line Plot')
plt.xlabel("Size")
plt.ylabel("Tip")
In [8]:
sns.lineplot(x='size',y='tip',data=tips,hue='time', style='time',palette=['red','blue'],markers=['o','^'])
plt.title('Line Plot')
plt.xlabel("Size",fontsize=15)
plt.ylabel("Tip",fontsize=15)
In [9]:
#now increasing the size of the figure
In [10]:
plt.figure(figsize=(16,9))
sns.lineplot(x='size',y='tip',data=tips,hue='time', style='time',palette=['red','blue'],markers=['o','^'])
plt.title('Line Plot')
plt.xlabel("Size",fontsize=15)
plt.ylabel("Tip",fontsize=15)
In [11]:
#now bringing it into grid
In [12]:
plt.figure(figsize=(16,9))
sns.set(style='darkgrid')
sns.lineplot(x='size',y='tip',data=tips,hue='time', style='time',palette=['red','blue'],markers=['o','^'])
plt.title('Line Plot')
plt.xlabel("Size",fontsize=15)
plt.ylabel("Tip",fontsize=15)
In [13]:
#to save the above graph as a figure
In [14]:
plt.figure(figsize=(16,9))
sns.set(style='darkgrid')
sns.lineplot(x='size',y='tip',data=tips,hue='time', style='time',palette=['red','blue'],markers=['o','^'])
plt.title('Line Plot')
plt.xlabel("Size",fontsize=15)
plt.ylabel("Tip",fontsize=15)
plt.savefig("My first graph saved")
In [15]:
# now we will make distribution plot
In [16]:
tips_df=sns.load_dataset('tips')
In [18]:
sns.distplot(tips_df['size'])
Out[18]:
In [19]:
sns.distplot(tips_df['total_bill'])
Out[19]:
In [20]:
sns.distplot(tips_df['total_bill'],bins=5)
Out[20]:
In [21]:
sns.distplot(tips_df['total_bill'],bins=[0,10,15,20,25,30,35,40,45,50,55])
Out[21]:
In [23]:
sns.distplot(tips_df['total_bill'],bins=[0,10,15,20,25,30,35,40,45,50,55],hist=False)
Out[23]:
In [24]:
sns.distplot(tips_df['total_bill'],bins=[0,10,15,20,25,30,35,40,45,50,55],kde=False)
Out[24]:
In [25]:
sns.distplot(tips_df['total_bill'],bins=[0,10,15,20,25,30,35,40,45,50,55],rug=True)
Out[25]:
In [26]:
sns.distplot(tips_df['total_bill'],bins=[0,10,15,20,25,30,35,40,45,50,55],color='red')
Out[26]:
In [27]:
sns.distplot(tips_df['total_bill'],bins=[0,10,15,20,25,30,35,40,45,50,55],axlabel='Total Bill')
Out[27]:
In [28]:
sns.distplot(tips_df['total_bill'],bins=[0,10,15,20,25,30,35,40,45,50,55],label="Bill")
plt.legend()
Out[28]:
In [29]:
sns.distplot(tips_df['total_bill'],bins=[0,10,15,20,25,30,35,40,45,50,55],label="Bill")
plt.title("Histogram")
Out[29]:
<matplotlib.legend.Legend at 0x26907692518>
In [30]:
sns.set()
sns.distplot(tips_df['total_bill'],bins=[0,10,15,20,25,30,35,40,45,50,55],label="Bill")
plt.title("Histogram")
plt.legend()
Out[30]:
In [34]:
plt.figure(figsize=(9,6))
sns.set()
sns.distplot(tips_df['total_bill'],bins=[0,10,15,20,25,30,35,40,45,50,55],label="Bill")
plt.title("Histogram")
plt.legend()
Out[34]:
In [35]:
sns.set()
sns.distplot(tips_df['total_bill'],bins=[0,10,15,20,25,30,35,40,45,50,55],label="Bill",hist_kws={'color':'g'})
plt.title("Histogram")
plt.legend()
Out[35]:
In [36]:
# in the above we only changed histogrm colour and not KDes
In [37]:
sns.set()
sns.distplot(tips_df['total_bill'],bins=[0,10,15,20,25,30,35,40,45,50,55],label="Bill",hist_kws={'color':'g','edgecolor':'b','linewidth':5})
plt.title("Histogram")
plt.legend()
<matplotlib.legend.Legend at 0x26907baf4e0>
In [38]:
sns.set()
sns.distplot(tips_df['total_bill'],bins=[0,10,15,20,25,30,35,40,45,50,55],label="Bill",hist_kws={'color':'g','edgecolor':'b','linewidth':5,'linestyle':'--'})
plt.title("Histogram")
plt.legend()
Out[38]:
In [39]:
sns.set()
sns.distplot(tips_df['total_bill'],bins=[0,10,15,20,25,30,35,40,45,50,55],label="Bill",hist_kws={'color':'g','edgecolor':'b','linewidth':5,'linestyle':'--','alpha':0.9})
plt.title("Histogram")
plt.legend()
Out[39]:
In [40]:
sns.set()
sns.distplot(tips_df['total_bill'],bins=[0,10,15,20,25,30,35,40,45,50,55],label="Bill",hist_kws={'color':'g','edgecolor':'b','linewidth':5,'linestyle':'--','alpha':0.9},kde_kws={'color':'r','linewidth':5,'linestyle':'--','alpha':0.9})
plt.title("Histogram")
plt.legend()
Out[40]:
In [41]:
#the above example also includes changes to KDE
In [44]:
sns.set()
sns.distplot(tips_df['total_bill'],bins=[0,10,15,20,25,30,35,40,45,50,55],label="Bill",
hist_kws={'color':'g','edgecolor':'b','linewidth':5,'linestyle':'--','alpha':0.9},
kde_kws={'color':'r','linewidth':5,'linestyle':'--','alpha':0.9},
rug=True,
rug_kws={'color':'r','edgecolor':'k','linewidth':5,'linestyle':'--','alpha':0.9})
plt.title("Histogram")
plt.legend()
Out[44]:
In [45]:
#now we will make joint plot
In [46]:
sns.jointplot(tips['total_bill'],tips['tip'],tips)
Out[46]:
In [47]:
sns.jointplot(tips['total_bill'],tips['tip'],tips,kind='hex')
Out[47]:
In [48]:
#now we will do pair plot
In [49]:
sns.pairplot(tips)
Out[49]:
In [50]:
tips.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 244 entries, 0 to 243
Data columns (total 7 columns):
total_bill 244 non-null float64
tip 244 non-null float64
sex 244 non-null category
smoker 244 non-null category
day 244 non-null category
time 244 non-null category
size 244 non-null int64
dtypes: category(4), float64(2), int64(1)
memory usage: 7.2 KB
In [51]:
#in the above graph, it made graph of 3X3 of the distribution column which are all float64 in the above example
In [52]:
sns.pairplot(tips,hue='sex')
Out[52]:
In [53]:
sns.pairplot(tips,hue='day')
Out[53]:
In [54]:
sns.pairplot(tips,hue='smoker')
Out[54]:
In [55]:
#now we will category column graph
In [56]:
sns.barplot(x=tips_df['day'],y=tips_df['total_bill'])
Out[56]:
In [58]:
sns.barplot(x=tips_df['day'],y=tips_df['total_bill'],hue=tips_df['sex'])
Out[58]:
In [59]:
sns.barplot(x='day',y='total_bill',hue='sex',data=tips_df)
Out[59]:
In [61]:
sns.barplot(x='day',y='total_bill',hue='sex',data=tips_df,order=['Sun','Sat','Fri','Thur'])
Out[61]:
In [62]:
sns.barplot(x='day',y='total_bill',hue='sex',data=tips_df,order=['Sun','Sat','Fri','Thur'],hue_order=['Female','Male'])
Out[62]:
In [65]:
sns.barplot(x='day',y='total_bill',hue='sex',data=tips_df,order=['Sun','Sat','Fri','Thur'],hue_order=['Female','Male'],palette='Set1')
Out[65]:
In [ ]:



































No comments:
Post a Comment