/ Python And R Data science skills: 89 violin and more plots

Sunday 18 February 2018

89 violin and more plots

https://vlrtraining.com/courses/python-data-science-beginner-tutorial 89 violin and more 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
In [2]:
sns.boxplot(x="day", y="total_bill", hue="smoker",data=tips, )
Out[2]:
<matplotlib.axes._subplots.AxesSubplot at 0xb650470>

violinplot

A violin plot plays a similar role as a box and whisker plot. It shows the distribution of quantitative data across several levels of one (or more) categorical variables such that those distributions can be compared. Unlike a box plot, in which all of the plot components correspond to actual datapoints, the violin plot features a kernel density estimation of the underlying distribution.

In [39]:
sns.violinplot(x="day", y="total_bill", data=tips)
Out[39]:
<matplotlib.axes._subplots.AxesSubplot at 0xd6f8a58>
In [18]:
age=[11,12,13,14,15,11,12,13,14,15]
waight=[20,30,30,20,13,23,33,13,20,21]
In [19]:
sns.violinplot(age,waight)
Out[19]:
<matplotlib.axes._subplots.AxesSubplot at 0xbe94748>
In [20]:
sns.violinplot(x="day", y="total_bill", data=tips,hue="sex")
Out[20]:
<matplotlib.axes._subplots.AxesSubplot at 0xbf15b00>
In [22]:
sns.violinplot(x="day", y="total_bill", data=tips,hue="sex",split=True)
Out[22]:
<matplotlib.axes._subplots.AxesSubplot at 0xbfdbdd8>

stripplot

The stripplot will draw a scatterplot where one variable is categorical. A strip plot can be drawn on its own, but it is also a good complement to a box or violin plot in cases where you want to show all observations along with some representation of the underlying distribution.

The swarmplot is similar to stripplot(), but the points are adjusted (only along the categorical axis) so that they don’t overlap. This gives a better representation of the distribution of values, although it does not scale as well to large numbers of observations (both in terms of the ability to show all the points and in terms of the computation needed to arrange them).

In [40]:
sns.stripplot(x="day", y="total_bill", data=tips)
#sns.violinplot(x="day", y="total_bill", data=tips,hue="sex",split=True)
Out[40]:
<matplotlib.axes._subplots.AxesSubplot at 0xd764fd0>
In [41]:
sns.stripplot(x="day", y="total_bill", data=tips,jitter=True)
Out[41]:
<matplotlib.axes._subplots.AxesSubplot at 0xd786400>
In [42]:
sns.stripplot(x="day", y="total_bill", data=tips,hue='sex',jitter=True)
Out[42]:
<matplotlib.axes._subplots.AxesSubplot at 0xd7d8550>
In [43]:
sns.stripplot(x="day", y="total_bill", data=tips,hue='sex',jitter=True,split=True)
C:\Users\venkat\Anaconda3\lib\site-packages\seaborn\categorical.py:2586: UserWarning: The `split` parameter has been renamed to `dodge`.
  warnings.warn(msg, UserWarning)
Out[43]:
<matplotlib.axes._subplots.AxesSubplot at 0xd820898>
In [29]:
sns.swarmplot(x="day", y="total_bill", data=tips)
Out[29]:
<matplotlib.axes._subplots.AxesSubplot at 0xc30bbe0>
In [30]:
sns.swarmplot(x="day", y="total_bill",hue='sex',data=tips,  split=True)
C:\Users\venkat\Anaconda3\lib\site-packages\seaborn\categorical.py:2783: UserWarning: The `split` parameter has been renamed to `dodge`.
  warnings.warn(msg, UserWarning)
Out[30]:
<matplotlib.axes._subplots.AxesSubplot at 0xd346a90>
In [44]:
sns.violinplot(x="day", y="total_bill", data=tips)
sns.swarmplot(x="day", y="total_bill", data=tips)
Out[44]:
<matplotlib.axes._subplots.AxesSubplot at 0xd88fe80>
In [45]:
sns.violinplot(x="day", y="total_bill", data=tips)
sns.swarmplot(x="day", y="total_bill", data=tips,color="Black")
Out[45]:
<matplotlib.axes._subplots.AxesSubplot at 0xd94b5c0>
In [46]:
sns.violinplot(x="tip", y="day", data=tips)
sns.swarmplot(x="tip", y="day", data=tips,color='black',size=3)
Out[46]:
<matplotlib.axes._subplots.AxesSubplot at 0xd9621d0>

factorplot

factorplot is the most general form of a categorical plot. It can take in a kind parameter to adjust the plot type:

In [35]:
sns.factorplot(x='sex',y='total_bill',data=tips,kind='bar')
Out[35]:
<seaborn.axisgrid.FacetGrid at 0xd47bdd8>
In [38]:
sns.factorplot(x='sex',y='total_bill',data=tips,kind='violin')
Out[38]:
<seaborn.axisgrid.FacetGrid at 0xd5a1588>

No comments:

Post a Comment