/ Python And R Data science skills: 88 box and count Categorical Plots

Sunday, 18 February 2018

88 box and count Categorical Plots

https://vlrtraining.com/courses/python-data-science-beginner-tutorial 88 box and count Categorical Plots
In [1]:
import seaborn as sns
%matplotlib inline
tips = sns.load_dataset('tips')
tips.head(1)
Out[1]:
total_bill tip sex smoker day time size
0 16.99 1.01 Female No Sun Dinner 2

countplot

This is essentially the same as barplot except the estimator is explicitly counting the number of occurrences. Which is why we only pass the x value:

In [5]:
sns.countplot(x='sex',data=tips)
Out[5]:
<matplotlib.axes._subplots.AxesSubplot at 0x85aa240>
In [7]:
sns.countplot(x='size',data=tips)
Out[7]:
<matplotlib.axes._subplots.AxesSubplot at 0xba22320>
In [8]:
sns.countplot(x='total_bill',data=tips)
Out[8]:
<matplotlib.axes._subplots.AxesSubplot at 0xba5b668>

boxplot and violinplot

boxplots and violinplots are used to shown the distribution of categorical data. A box plot (or box-and-whisker plot) shows the distribution of quantitative data in a way that facilitates comparisons between variables or across levels of a categorical variable. The box shows the quartiles of the dataset while the whiskers extend to show the rest of the distribution, except for points that are determined to be “outliers” using a method that is a function of the inter-quartile range.

In [9]:
sns.boxplot(x="day", y="total_bill", data=tips,palette='rainbow')
Out[9]:
<matplotlib.axes._subplots.AxesSubplot at 0xba9ae80>
In [10]:
# Can do entire dataframe with orient='h'
sns.boxplot(data=tips,palette='rainbow',orient='h')
Out[10]:
<matplotlib.axes._subplots.AxesSubplot at 0xbce0668>
In [12]:
sns.boxplot(x="day", y="total_bill", hue="smoker",data=tips, )
Out[12]:
<matplotlib.axes._subplots.AxesSubplot at 0xc0a2240>

No comments:

Post a Comment