Vis u ali z ing regressions IN TR OD U C TION TO DATA VISU AL IZATION IN P YTH ON Br y an Van de Ven Core De v eloper of Bokeh
Seaborn h � p :// seaborn . p y data . org / INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Recap : pandas DataFrames Labelled tab u lar data str u ct u re Labels on ro w s : index Labels on col u mns : columns Col u mns are pandas Series INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Tips DataFrame total _ bill tip se x smoker da y time si z e 0 16.99 1.01 Female No S u n Dinner 2 1 10.34 1.66 Male No S u n Dinner 3 2 21.01 3.5 Male No S u n Dinner 3 3 23.68 3.31 Male No S u n Dinner 2 4 24.59 3.61 Female No S u n Dinner 4 ... ... ... ... ... ... ... ... INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Linear regression plots 95% con � dence inter v al highlighted INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Using lmplot () import pandas as pd import matplotlib.pyplot as plt import seaborn as sns tips = sns.load_dataset('tips') sns.lmplot(x='total_bill', y='tip', data=tips) plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Factors total _ bill tip se x smoker da y time si z e 0 16.99 1.01 Female No S u n Dinner 2 1 10.34 1.66 Male No S u n Dinner 3 2 21.01 3.5 Male No S u n Dinner 3 3 23.68 3.31 Male No S u n Dinner 2 4 24.59 3.61 Female No S u n Dinner 4 ... ... ... ... ... ... ... ... INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Gro u ping factors ( same plot ) INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Using h u e sns.lmplot(x='total_bill', y='tip', data=tips, hue='sex', palette='Set1') plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Gro u ping factors ( s u bplots ) INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Using col sns.lmplot(x='total_bill', y='tip', data=tips, col='sex') plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Resid u al plots INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Using residplot () sns.residplot(x='age',y='fare', data=tips, color='indianred') plt.show() Similar arg u ments as lmplot() b u t more � e x ible x , y can be arra y s or strings data is DataFrame ( optional ) Optional arg u ments ( e . g ., color ) as in matplotlib INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Let ' s practice ! IN TR OD U C TION TO DATA VISU AL IZATION IN P YTH ON
Vis u ali z ing u ni v ariate distrib u tions IN TR OD U C TION TO DATA VISU AL IZATION IN P YTH ON Br y an Van de Ven Core De v eloper of Bokeh
Vis u ali z ing data Uni v ariate → " one v ariable " Vis u ali z ation techniq u es for sampled u ni v ariate data Strip plots S w arm plots Violin plots INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Strip plot INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Using stripplot () sns.stripplot(y='tip', data=tips) plt.ylabel('tip ($)') plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Gro u ping w ith stripplot () sns.stripplot(x='day', y='tip', data=tip) plt.ylabel('tip ($)') plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Spreading o u t strip plots sns.stripplot(x='day', y='tip', data=tip, size=4, jitter=True) plt.ylabel('tip ($)') plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON
S w arm plot INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Using s w armplot () sns.swarmplot(x='day', y='tip', data=tips) plt.ylabel('tip ($)') plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON
More gro u ping INTRODUCTION TO DATA VISUALIZATION IN PYTHON
More gro u ping w ith s w armplot () sns.swarmplot(x='day', y='tip', data=tips, hue='sex') plt.ylabel('tip ($)') plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Changing orientation INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Changing orientation sns.swarmplot(x='tip', y='day', data=tips, hue='sex', orient='h') plt.xlabel('tip ($)') plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Violin plot INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Using v iolinplot () plt.subplot(1,2,1) sns.boxplot(x='day', y='tip', data=tips) plt.ylabel('tip ($)') plt.subplot(1,2,2) sns.violinplot(x='day', y='tip', data=tips) plt.ylabel('tip ($)') plt.tight_layout() plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Combining plots INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Combining plots sns.violinplot(x='day', y='tip', data=tips, inner=None, color='lightgray') sns.stripplot(x='day', y='tip', data=tips, size=4, jitter=True) plt.ylabel('tip ($)') plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Let ' s practice ! IN TR OD U C TION TO DATA VISU AL IZATION IN P YTH ON
Vis u ali z ing m u lti v ariate distrib u tions IN TR OD U C TION TO DATA VISU AL IZATION IN P YTH ON Br y an Van de Ven Core De v eloper of Bokeh
Vis u ali z ing data Bi v ariate → " t w o v ariables " M u lti v ariate → " m u ltiple v ariables " Vis u ali z ing relationships in m u lti v ariate data Joint plots Pair plots Heat maps INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Joint plot INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Using jointplot () sns.jointplot(x= 'total_bill', y= 'tip', data=tips) plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Joint plot u sing KDE INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Using kde = Tr u e sns.jointplot(x='total_bill', y= 'tip', data=tips, kind='kde') plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Pair plot INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Using pairplot () sns.pairplot(tips) plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Using pairplot () w ith h u e sns.pairplot(tips, hue='sex') plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Co v ariance heat map of tips data INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Using heatmap () print(covariance) total_bill tip size total_bill 1.000000 0.675734 0.598315 tip 0.675734 1.000000 0.489299 size 0.598315 0.489299 1.000000 sns.heatmap(covariance) plt.title('Covariance plot') plt.show() INTRODUCTION TO DATA VISUALIZATION IN PYTHON
Let ' s practice ! IN TR OD U C TION TO DATA VISU AL IZATION IN P YTH ON
Recommend
More recommend