In [1]:
import seaborn as sns
%matplotlib inline
In [2]:
tips = sns.load_dataset('tips')
In [3]:
tips.head(5)
Out[3]:
In [6]:
#find dist of total bills
sns.distplot(tips['total_bill'])
Out[6]:
It is often useful to overlay the mean and SD with the histograms, below is one way to do it.
In [13]:
tips.total_bill.mean()
Out[13]:
In [20]:
tips_mean = tips.total_bill.mean()
tips_sd = tips.total_bill.std()
ax = sns.distplot(tips['total_bill'])
# plot mean in black
ax.axvline(x=tips_mean, color='black', linestyle='dashed')
# plot mean +- 1SD in red, dotted
ax.axvline(x=tips_mean + tips_sd, color='red', linestyle='dotted')
ax.axvline(x=tips_mean - tips_sd, color='red', linestyle='dotted')
# title
ax.set_title('$\mu = {}$ | $\sigma = {}$'.format(round(tips_mean, 2), round(tips_sd, 2)))
Out[20]:
You can change things like bin
, kde
flags to customize the plot
In [5]:
sns.distplot(tips['total_bill'], kde=False, bins=35)
Out[5]:
In [6]:
sns.jointplot(x=tips['total_bill'], y=tips['tip'])
Out[6]:
You can use the kind
argument to change the scatter
to hex
, reg
etc
In [102]:
jgrid = sns.jointplot(x='min_season', y='max_wind_merged', data=hurricanes_ipl,
kind='reg', joint_kws={'line_kws':{'color':'green'}}, height=7, space=0.5)
j = jgrid.annotate(stats.pearsonr)
j = jgrid.ax_joint.set_title('Does hurricane wind speed increase over time?')
In [7]:
sns.jointplot(x=tips['total_bill'], y=tips['tip'], kind='hex')
Out[7]:
In [8]:
sns.jointplot(x=tips['total_bill'], y=tips['tip'], kind='reg') #regression
Out[8]:
In [10]:
sns.pairplot(tips, hue='sex')
Out[10]:
In [11]:
sns.rugplot(tips['total_bill'])
Out[11]: