Jovian
⭐️
Sign In
In [3]:
import seaborn as sns
import matplotlib.pyplot as plt
In [4]:
data = sns.load_dataset("titanic")
sns.set()

# Set context to "talk"
sns.set_context("talk",font_scale=1)  # other predefined contexts are 'notebook','paper','poster'

In [5]:
data.head()
Out[5]:
In [6]:
sns.swarmplot(x="class", y="fare", data=data)

# Show plot
plt.show()
Notebook Image
In [7]:
import matplotlib.pyplot as plt 
import seaborn as sns 
  
# x axis values 
x =['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul','Aug','Sep','Oct','Nov',"Dec"] 
  
# y axis values 
y =[10,14,8,26,9,35,69,36,45,50,41,62] 
  
# plotting strip plot
ax = sns.stripplot(x, y); 
  
# giving labels to x-axis and y-axis 
ax.set(xlabel ='------Months-----', ylabel ='-------Days------') 
  
# giving title to the plot 
plt.title('-------My first graph-------'); 
  
# function to show plot 
plt.show() 
Notebook Image
In [8]:
import seaborn as sns
%matplotlib inline
sns.set(style='whitegrid')
data = sns.load_dataset('tips')
ax = sns.stripplot(x = data['total_bill'],y=data['tip'])
Notebook Image
In [9]:
from matplotlib import pyplot as plt
import seaborn as sns
# will display plot inside the notebook
%matplotlib inline 
import pandas as pd
df = pd.read_csv('datasets/tips.csv') # loading dataset as a dataframe
df.head()
Out[9]:
In [10]:
sns.lmplot(x ='total_bill',y='tip', data=df , fit_reg = False , hue = 'size')
Out[10]:
<seaborn.axisgrid.FacetGrid at 0x1fcbea23e80>
Notebook Image
In [30]:
from matplotlib import pyplot as plt
import seaborn as sns
# will display plot inside the notebook
%matplotlib inline 
import pandas as pd
df = pd.read_csv('datasets/tips.csv', index_col=0) # loading dataset as a dataframe
print(df.head())
sns.lmplot(x ='total_bill',y='tip', data=df , fit_reg = False , hue = 'size') # hue parameter determines which column in the data frame should be used for colour encoding

plt.ylim(0,None) # Tweaking using matplolib for sensible axes limits
plt.xlim(0,None)
total_bill tip sex smoker day time size 1 16.99 1.01 Female No Sun Dinner 2 2 10.34 1.66 Male No Sun Dinner 3 3 21.01 3.50 Male No Sun Dinner 3 4 23.68 3.31 Male No Sun Dinner 2 5 24.59 3.61 Female No Sun Dinner 4
Out[30]:
(0, 53.83025985113406)
Notebook Image

Box plot

In [13]:
df1= pd.read_csv('datasets/tips.csv',index_col=0) # loading dataset as a datafram
print(df1)
df2=df1.drop(['sex','day','time'],axis=1)
sns.boxplot(data=df2)
total_bill tip sex smoker day time size 1 16.99 1.01 Female No Sun Dinner 2 2 10.34 1.66 Male No Sun Dinner 3 3 21.01 3.50 Male No Sun Dinner 3 4 23.68 3.31 Male No Sun Dinner 2 5 24.59 3.61 Female No Sun Dinner 4 .. ... ... ... ... ... ... ... 240 29.03 5.92 Male No Sat Dinner 3 241 27.18 2.00 Female Yes Sat Dinner 2 242 22.67 2.00 Male Yes Sat Dinner 2 243 17.82 1.75 Male No Sat Dinner 2 244 18.78 3.00 Female No Thur Dinner 2 [244 rows x 7 columns]
Out[13]:
<matplotlib.axes._subplots.AxesSubplot at 0x1fcbead4a20>
Notebook Image

violin plot

In [45]:
dataset = sns.load_dataset('titanic')
print(dataset.head())
sns.set_style('white')
sns.set_context("notebook",font_scale=2) 
sns.violinplot(x = 'class',y ='fare',data=dataset)
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 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
Out[45]:
<matplotlib.axes._subplots.AxesSubplot at 0x1fcc38e71d0>
Notebook Image

Overlaying plots

In [21]:
dataset1=dataset.tail(50) # last 50 rows in the dataset
plt.figure(figsize=(11,7)) # set fig size using matplotlib
sns.violinplot(x = 'class' , y = 'fare' , data = dataset1 , inner = None)#To remove the bars inside we set None to inner

sns.swarmplot(x = 'class' , y = 'fare' , data = dataset1, color = 'black' , alpha = 0.7) # set alpha value for transparency

plt.title('CLASS & FARE RATIO')
Out[21]:
Text(0.5, 1.0, 'CLASS & FARE RATIO')
Notebook Image

Heatmap

In [24]:
plt.figure(figsize=(10,7))
cor = dataset.corr()
sns.heatmap(cor)
Out[24]:
<matplotlib.axes._subplots.AxesSubplot at 0x1fcc109d4a8>
Notebook Image

Histogram

In [31]:
plt.figure(figsize=(10,7))
sns.distplot(df.total_bill)
Out[31]:
<matplotlib.axes._subplots.AxesSubplot at 0x1fcc1924240>
Notebook Image
In [ ]:
 
In [43]:
plt.figure(figsize=(8,6))
sns.countplot(x='class' , data = dataset)
Out[43]:
<matplotlib.axes._subplots.AxesSubplot at 0x1fcc36d50b8>
Notebook Image

Factor plot

In [72]:
plt.figure(figsize=(10,10))
fact = sns.factorplot( x = 'embark_town', y = 'fare' , data = dataset , hue = 'class' , col = 'class' , kind = 'strip')
fact.set_xticklabels(rotation = -45)
Out[72]:
<seaborn.axisgrid.FacetGrid at 0x1fccac713c8>
<Figure size 720x720 with 0 Axes>
Notebook Image

Density plot

In [75]:
plt.figure(figsize=(6,6))
sns.kdeplot (df1.tip,df1.total_bill)
Out[75]:
<matplotlib.axes._subplots.AxesSubplot at 0x1fccca472b0>
Notebook Image

Joint - Distribution plot

In [77]:
plt.figure(figsize=(7,6))
sns.jointplot(x='age', y ='fare' , data = dataset.head(100))
Out[77]:
<seaborn.axisgrid.JointGrid at 0x1fcccac7908>
<Figure size 504x432 with 0 Axes>
Notebook Image
In [ ]:
 
In [ ]:
 
In [ ]: