Types of plotting:
- Distribution plots
- Categorical plots
- Matrix plots
DISTRIBUTION PLOTS
- Distplot:
Sns.distplot (df [ ‘ col’ ], kde = )
Kde provides an estimation line for the resulting histogram chart
- Joint plot
Compare two distributions and plots a scatter plot by default
Sns.jointplot (x = , y = , data = , kind = ‘reg’ / ‘hex’ )
- Kde plot:
Sns.kdeplot ( df [ ‘ col ‘ ] )
- Pair plot
Plot the relationship across the entire data frame’s numerical value.
Sns.pairplot ( dataframe )
To view in table use sns.load_dataset
In hue parameter we can pass categorical data
- Rug plot:
Plot a single column of data points in a data frame as sticks. Where values will be more, plot will be denser
Sns.rugplot (dataframe [ ‘col’ ] )
- Styling
Sns.set_style ( ‘white’ ) → darkgrid / whitegrid
Plt.figure (figsize = (8, 2) )
sns.set_context ( ‘paper’ / ‘talk’ / ‘poster’, fontscale = 0.4) changes the figure zoom value
Sns.despint ( right = False) → removes right line in pairplot
CATEGORICAL PLOTS
- Bar Plot
The data will be aggregated based upon their means by default. For other aggregation we use estimator. Part of the descriptive data. Sns.barplot ( x = , y = , data = , estimate = np.median / var / cov )
- Count Plot
It is almost like bar plot but the estimator is just simply count the number of occurrences
Sns.countplot ( x= , y = , data = )
- Box Plot
It allow us to compare different variables and show us the quantiles of data
Sns.boxplot ( x =, y= , data = , hue = )
Plt.legend ( loc = 0 )
1: upper right 2: upper left 3: lower left 4: lower righ
The centred line shows the median. The whiskers are extended up and down on the boxes.
Hue provides us an additional way to add another category
- Violin Plot
Combination of box plot and kde plot
Sns.violinplot ( x=, y = , data = , hue = , split = True / false)
Split allows us to compare how the categories compare to each other.
- Strip Plot
It draws a scatter plot representing all the different data points
Sns.stripplot ( x= , y = , data = , jitter = True , hue = , dodge = True )
Jitter: spreads the data points
Dodge: makes the two variable points separated from each other
- Swarm Plot:
Same as strip plot but the points are going to be adjusted so that they don’t overlap
Sns.swarmplot ( x = , y = , data = )
MATRIX PLOTS
- Heat maps
Crash_matrix = crash_df.corr ()
Sns.heatmap ( Crash_matrix, annot = True, cmap = ‘blues’ )
Annot: Numbers in the centre of each part of heat map
Correlation function in seaborn: Tells how influential a variable is on the result. dataframe.corr()
dataframe.pivot_table (index = , columns = , values = )
Pivot_table: another way to get your columns and put them into rows and correlate all the data
- Cluster maps
Sns.clustermap (iris, cmap = , standard_scale = ))
- Pair Grid
It is used when you want to get specific control over what plot and what data shows up where
Iris = sns.pairgrid ( iris , hue = ‘species’ )
Iris.map ( plt.scatter)
Or Iris.map_diag ( plt.hist)
Or Iris.map_offdiag ( plt.scatter)
- Facet Grid
We can print multiple plots in a grid
- Regression Plots