In [1]:
import matplotlib.pyplot as plt
import seaborn as sns, numpy as np
from pylab import *
In [2]:
np.random.seed(0)
x = np.random.randn(100)
x
Out[2]:
In [3]:
sns.set(rc={"figure.figsize": (10, 4)});
ax = sns.distplot(x)
plt.show()
In [4]:
tips = sns.load_dataset("tips")
tips
Out[4]:
In [5]:
sns.distplot(tips["total_bill"])
plt.show()
In [6]:
sns.distplot(tips["total_bill"], hist = False)
plt.show()
In [7]:
sns.distplot(tips["total_bill"])
plt.show()
In [8]:
#kde(Kernel density estimation) - plotting the shape of a distribution
sns.distplot(tips["total_bill"], kde = False)
plt.show()
In [9]:
sns.distplot(tips["total_bill"], color="r")
plt.show()
In [10]:
sns.distplot(tips["total_bill"], color="#d7f039", vertical=False)
plt.show()
In [11]:
sns.distplot(tips["total_bill"], color="#d7f039", vertical=True)
plt.show()
In [12]:
# Modify histogram with bins
bins = [1,5,10,15,20,25,30,35,40,45,50,55] # list
plt.figure(figsize=(16,9))
sns.set()
sns.distplot(tips["total_bill"], bins = bins)
plt.xticks(bins)
plt.title("Histogram of Total Bill")
plt.show()
In [13]:
plt.figure(figsize=(16,9))
sns.set()
sns.distplot(tips["total_bill"],
hist_kws = {'color':'#3e70ea', 'edgecolor':'#b1c0e5',
'linewidth':5, 'linestyle':'--', 'alpha':0.9})
plt.show()
In [14]:
sns.set(rc={"figure.figsize": (8, 4)});
np.random.seed(0)
x = np.random.randn(100)
x
Out[14]:
In [15]:
subplot(2,2,1)
ax = sns.distplot(x)
subplot(2,2,2)
ax = sns.distplot(x, rug=False, hist=False)
subplot(2,2,3)
ax = sns.distplot(x, vertical=True)
subplot(2,2,4)
ax = sns.kdeplot(x, shade=True, color="r")
plt.show()
In [16]:
titanic=sns.load_dataset('titanic')
titanic
Out[16]:
In [17]:
age1 = titanic['age'].dropna()
age1
Out[17]:
In [18]:
sns.distplot(age1)
plt.show()
In [19]:
sns.distplot(age1, bins=30, kde=False)
plt.show()
In [20]:
fig, axes = plt.subplots(1,2)
sns.distplot(age1,ax=axes[0])
plt.grid(True)
sns.distplot(age1,rug=True,ax=axes[1])
plt.show()