# Plotting with seaborn¶

## 0. Installing the Library¶

• Run the following code in your command-line prompt:
conda install seaborn
• Depending on how you installed Python, you might need to try the following code instead (if the previous one doesn't work):
pip install seaborn

## 1. Overview of seaborn Plotting Functions¶

• seaborn is a Python data visualization library based on Matplotlib.
• You can view it as a modified, improved version of Matplotlib with much more user-friendly interface and syntax.

### 1.1 Figure-level vs. Axes-level Functions¶

• seaborn functions are classified into 2 groups: "axes-level" and "figure-level".
• Axes-level functions plot data onto a single matplotlib.pyplot.Axes object, which is the return value of the function.
• Figure-level functions interact with Matplotlib through a seaborn object, usually a FacetGrid that manages the figure.

### 1.2 Plotting modules¶

• seaborn plotting functions are categorized into one of the following modules:

• In each module, there is a single figure-level function, which offers an interface to its various axes-level functions.
• For example, displot() is the figure-level function of the distribution module. Its default behavior is to draw a histogram using the same code as histplot() behind scenes.
• Instead of a histogram, we might want a kernel density plot instead (using kdeplot()).
• We can do so still with the displot() function but with the kind parameter set to 'kde':
• We can plot a histogram for each Iris specie!
• The most useful feature offered by the figure-level functions is that they can easily create figures with multiple subplots.
• For example, instead of stacking, we can “facet” them by plotting each distribution across the columns of the figure:

### 1.3 Plotting themes¶

• seaborn creates much more beautiful plots than Matplotlib due to the options to set theme to the plots.
• All available seaborn themes can be found here.

## 2. Basic Plots with seaborn¶

### 2.1 Histograms¶

• To plot a histogram using seaborn, use the sns.histplot() or the sns.displot() function.

### 2.2 Boxplots¶

• To plot a boxplot using seaborn, use the sns.boxplot() function:
• For a horizontal boxplot, just assign the variable to the x parameter of the function call instead.
• What's about a boxplot for each day of the week?
• We can even add side by side boxplots for smoker and non-smoker (with different colors)!

### 2.3. Scatterplots¶

• Similar to boxplots and histograms, use sns.scatterplot() to plot a scatterplot with seaborn.
• An example from the seaborn gallery on a complex scatterplot.
• You can find examples on different types of plots there.

### 2.4. Scatterplot Matrix¶

• This is one of the most powerful and important plot in EDA (exploratory data analysis).
• It's always a good idea to plot the scatterplot matrix when looking at a new dataset.