Friday, November 29, 2019

Learning Datascience Day 7


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")
plt.show()

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)
plt.show()

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)
plt.show()

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)
plt.show()

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")
plt.show()

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]:
<matplotlib.axes._subplots.AxesSubplot at 0x26907547f98>

In [19]:
sns.distplot(tips_df['total_bill'])
Out[19]:
<matplotlib.axes._subplots.AxesSubplot at 0x269078f5390>

In [20]:
 sns.distplot(tips_df['total_bill'],bins=5)
Out[20]:
<matplotlib.axes._subplots.AxesSubplot at 0x269079119e8>

In [21]:
sns.distplot(tips_df['total_bill'],bins=[0,10,15,20,25,30,35,40,45,50,55])
Out[21]:
<matplotlib.axes._subplots.AxesSubplot at 0x26907969080>

In [23]:
sns.distplot(tips_df['total_bill'],bins=[0,10,15,20,25,30,35,40,45,50,55],hist=False)
Out[23]:
<matplotlib.axes._subplots.AxesSubplot at 0x26907a0b208>

In [24]:
sns.distplot(tips_df['total_bill'],bins=[0,10,15,20,25,30,35,40,45,50,55],kde=False)
Out[24]:
<matplotlib.axes._subplots.AxesSubplot at 0x26907360ef0>

In [25]:
sns.distplot(tips_df['total_bill'],bins=[0,10,15,20,25,30,35,40,45,50,55],rug=True)
Out[25]:
<matplotlib.axes._subplots.AxesSubplot at 0x269073d6cc0>

In [26]:
sns.distplot(tips_df['total_bill'],bins=[0,10,15,20,25,30,35,40,45,50,55],color='red')
Out[26]:
<matplotlib.axes._subplots.AxesSubplot at 0x269079ef3c8>

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]:
<matplotlib.axes._subplots.AxesSubplot at 0x269074db518>

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]:
<matplotlib.legend.Legend at 0x26907351748>

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")
plt.legend()

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]:
<matplotlib.legend.Legend at 0x2690770f0f0>

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]:
<matplotlib.legend.Legend at 0x2690776d6a0>

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]:
<matplotlib.legend.Legend at 0x26907b4ecf8>

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()
Out[37]:

<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]:
<matplotlib.legend.Legend at 0x26907c09860>

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]:
<matplotlib.legend.Legend at 0x26907d15128>

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]:
<matplotlib.legend.Legend at 0x26907da5048>

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]:
<matplotlib.legend.Legend at 0x26908e7e978>

In [45]:
#now we will make joint plot
In [46]:
sns.jointplot(tips['total_bill'],tips['tip'],tips)
Out[46]:
<seaborn.axisgrid.JointGrid at 0x26908f34eb8>

In [47]:
sns.jointplot(tips['total_bill'],tips['tip'],tips,kind='hex')
Out[47]:
<seaborn.axisgrid.JointGrid at 0x26909040ef0>

In [48]:
#now we will do pair plot
In [49]:
sns.pairplot(tips)
Out[49]:
<seaborn.axisgrid.PairGrid at 0x269091a2dd8>

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]:
<seaborn.axisgrid.PairGrid at 0x26909504f98>

In [53]:
sns.pairplot(tips,hue='day')
Out[53]:
<seaborn.axisgrid.PairGrid at 0x26909c61a20>

In [54]:
sns.pairplot(tips,hue='smoker')
Out[54]:
<seaborn.axisgrid.PairGrid at 0x2690a389fd0>

In [55]:
#now we will category column graph
In [56]:
sns.barplot(x=tips_df['day'],y=tips_df['total_bill'])
Out[56]:
<matplotlib.axes._subplots.AxesSubplot at 0x2690b9254a8>

In [58]:
sns.barplot(x=tips_df['day'],y=tips_df['total_bill'],hue=tips_df['sex'])
Out[58]:
<matplotlib.axes._subplots.AxesSubplot at 0x2690b970d30>

In [59]:
sns.barplot(x='day',y='total_bill',hue='sex',data=tips_df)
Out[59]:
<matplotlib.axes._subplots.AxesSubplot at 0x2690ba3e518>

In [61]:
sns.barplot(x='day',y='total_bill',hue='sex',data=tips_df,order=['Sun','Sat','Fri','Thur'])
Out[61]:
<matplotlib.axes._subplots.AxesSubplot at 0x2690bcc8400>

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]:
<matplotlib.axes._subplots.AxesSubplot at 0x2690bd43a20>

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]:
<matplotlib.axes._subplots.AxesSubplot at 0x2690bde3d68>

In [ ]:




No comments:

Post a Comment

Featured Post

Ichimoku cloud

Here how you read a ichimoku cloud 1) Blue Converse line: It measures short term trend. it also shows minor support or resistance. Its ve...