Data Visualization using Seaborn
Data Visualization is an effective way to analyze information visually. Visualizations make it easier to explore and extract relevant information from the data by identifying patterns, relationships, outliers, and much more. In this blog will discuss Data Visualization using Seaborn.
We are back with Data Visualization using the Seaborn tutorial. We have already learned Data Visualization using Matplotlib.
If Matplotlib “tries to make easy things easy and hard things possible”, seaborn tries to make a well-defined set of hard things easy too” — Michael Waskom (Creator of Seaborn).
In this blog on Data Visualization using Seaborn, we will be covering the following sections:
Content
- Introduction to Seaborn
- Why Use Seaborn Over Matplotlib?
- Installing Seaborn
- Importing Seaborn
- Getting Seaborn Datasets
- Creating Plots using Seaborn
- Creating Multiplot Grids
- Customizing Seaborn Plots
Introduction to Seaborn
Seaborn is a statistical plotting library in Python and is an extended version of Matplotlib. It supports complex visualizations and makes the plotting of graphs simple and intuitive. It can be used in Python scripts, Jupyter notebook, and web application servers.
Best-suited Data Visualization courses for you
Learn Data Visualization with these high-rated online courses
Why Use Seaborn Over Matplotlib?
- Seaborn uses less syntax as compared to Matplotlib. Hence, it is easier to use.
- It is easier to customize themes and high-level interfaces in Seaborn to make the plots more attractive and readable.
- Seaborn is much more functional and organized than Matplotlib. It is better integrated to work with Pandas DataFrames.
Installing Seaborn
Let’s start with installing the library in your working environment first:
\n \n <pre class="python" style="font-family:monospace">\n \n <span style="color: #808080;font-style: italic">\n \n #To install Matplotlib in Jupyter Notebook:\n \n pip install seaborn\n \n \n \n \n \n <span style="color: #808080;font-style: italic">\n \n #To install Matplotlib in Anaconda Prompt:\n \n conda install seaborn\n \n </span style="color: #808080;font-style: italic">\n \n </span style="color: #808080;font-style: italic">\n \n </pre class="python" style="font-family:monospace">
Once Seaborn is installed, ensure that you also install the necessary packages and libraries that Seaborn is dependent on:
- Pandas
- NumPy
- Matplotlib
- SciPy
Importing Seaborn
Now let’s import the Seaborn library along with the other libraries we might need today:
\n \n <pre class="python" style="font-family:monospace">\n \n <span style="color: #ff7700;font-weight:bold">\n \n import seaborn \n \n <span style="color: #ff7700;font-weight:bold">\n \n as sns\n \n \n \n <span style="color: #ff7700;font-weight:bold">\n \n import pandas \n \n <span style="color: #ff7700;font-weight:bold">\n as pd \n \n <span style="color: #ff7700;font-weight:bold">\n import numpy \n <span style="color: #ff7700;font-weight:bold">\n as np \n \n <span style="color: #ff7700;font-weight:bold">\n import matplotlib. \n <span style="color: black">\n pyplot \n <span style="color: #ff7700;font-weight:bold">\n as plt \n %matplotlib inline \n </span style="color: #ff7700;font-weight:bold"> \n </span style="color: black"> \n </span style="color: #ff7700;font-weight:bold"> \n </span style="color: #ff7700;font-weight:bold"> \n </span style="color: #ff7700;font-weight:bold"> \n </span style="color: #ff7700;font-weight:bold">\n \n </span style="color: #ff7700;font-weight:bold">\n \n </span style="color: #ff7700;font-weight:bold">\n \n </span style="color: #ff7700;font-weight:bold">\n \n </pre class="python" style="font-family:monospace">
Getting Seaborn Datasets
Seaborn has sample datasets available to plot to demonstrate its powerful plotting functions. You can get a list of those through the following command:
\n \n <pre class="python" style="font-family:monospace">\n \n <span style="color: #808080;font-style: italic">\n \n #available datasets in seaborn\n \n sns.\n \n <span style="color: black">\n \n get_dataset_names()\n \n </span style="color: black">\n \n </span style="color: #808080;font-style: italic">\n \n </pre class="python" style="font-family:monospace">
Let’s make use of the ‘tips’ dataset to understand how to visualize data using Seaborn.
Creating Plots using Seaborn
Load the dataset
Prior to creating our graphs, let’s check out the dataset:
\n \n <pre class="python" style="font-family:monospace">\n \n <span style="color: #808080;font-style: italic">\n \n #Read the dataset\n \n df \n \n <span style="color: #66cc66">\n \n = sns.\n \n <span style="color: black">\n \n load_dataset(\n \n <span style="color: #483d8b">\n 'tips' \n <span style="color: black">\n ) \n df. \n <span style="color: black">\n head() \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b">\n \n </span style="color: black">\n \n </span style="color: #66cc66">\n \n </span style="color: #808080;font-style: italic">\n \n </pre class="python" style="font-family:monospace">
Now, let’s move ahead with analyzing this dataset through visualizations.
Plots on Continuous Data
Line Graphs/Plots
Just like in Matplotlib, these graphs are the easiest to plot. Let’s create one to analyze the relationship between the billed and the tipped amount.
Here, the datapoints will plotted x (‘total_bill’) versus y (‘tip’) using lineplot() function:
\n \n <pre class="python" style="font-family:monospace">\n \n <span style="color: #808080;font-style: italic">\n \n #Line Plot\n \n sns.\n \n <span style="color: black">\n \n lineplot\n \n <span style="color: black">\n \n (x \n \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'total_bill' \n <span style="color: #66cc66">\n ,y \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'tip' \n <span style="color: #66cc66">\n , data \n <span style="color: #66cc66">\n = df \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66">\n \n </span style="color: black">\n \n </span style="color: black">\n \n </span style="color: #808080;font-style: italic">\n \n </pre class="python" style="font-family:monospace">
A basic line plot is generated as shown above.
Since Seaborn is based on Matplotlib, you can add different pyplot elements to interpret a graph better:
- Use plt.title() for setting a plot title
- Use plt.xlabel() and plt.ylabel() for labeling x and y-axis respectively
- Use plt.legend() for the observation variables
- Use plt.show() for displaying the plot
\n \n <pre class="python" style="font-family:monospace">\n \n sns.\n \n <span style="color: black">\n \n lineplot\n \n <span style="color: black">\n \n (x \n \n <span style="color: #66cc66">\n \n =\n \n <span style="color: #483d8b">\n 'total_bill' \n <span style="color: #66cc66">\n ,y \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'tip' \n <span style="color: #66cc66">\n , data \n <span style="color: #66cc66">\n = df \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n title \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n "Bill vs Tip" \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n xlabel \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n "Billed Amount" \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n ylabel \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n "Tipped Amount" \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n show \n <span style="color: black">\n ( \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b">\n \n </span style="color: #66cc66">\n \n </span style="color: black">\n \n </span style="color: black">\n \n </pre class="python" style="font-family:monospace">
A labeled and titled graph vastly improves its readability, right?
Scatter Plots
Close relative to line plots, scatter plots also reveal relationships between two numerical variables. Scatter plots can display:
- High/Low Negative Correlation
- High/Low Positive Correlation
- No Correlation
The function used for the scatter plot is scatterplot(), as shown below:
\n \n <pre class="python" style="font-family:monospace">\n \n <span style="color: #808080;font-style: italic">\n \n #Scatter Plot\n \n sns.\n \n <span style="color: black">\n \n scatterplot\n \n <span style="color: black">\n \n (x \n \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'total_bill' \n <span style="color: #66cc66">\n ,y \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'tip' \n <span style="color: #66cc66">\n , data \n <span style="color: #66cc66">\n = df \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n title \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n "Bill vs Tip" \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n xlabel \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n "Billed Amount" \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n ylabel \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n "Tipped Amount" \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n show \n <span style="color: black">\n ( \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66">\n \n </span style="color: black">\n \n </span style="color: black">\n \n </span style="color: #808080;font-style: italic">\n \n </pre class="python" style="font-family:monospace">
Regression Plots
They are just like scatter plots but with a regression line or a trend line. The function used for the regression plot is regplot(), as shown below:
\n \n <pre class="python" style="font-family:monospace">\n \n <span style="color: #808080;font-style: italic">\n \n #Regression Plot\n \n sns.\n \n <span style="color: black">\n \n regplot\n \n <span style="color: black">\n \n (x\n \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'total_bill' \n <span style="color: #66cc66">\n ,y \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'tip' \n <span style="color: #66cc66">\n ,data \n <span style="color: #66cc66">\n =df \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n title \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n "Bill vs Tip" \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n xlabel \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n "Billed Amount" \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n ylabel \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n "Tipped Amount" \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n show \n <span style="color: black">\n ( \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66">\n \n </span style="color: black">\n \n </span style="color: black">\n \n </span style="color: #808080;font-style: italic">\n \n </pre class="python" style="font-family:monospace">
As expected, the higher the billed amount, the higher is the tipped amount by a customer. Hence, the two variables are said to have a weak positive correlation.
Histograms
Histograms display the frequency/count values by forming bins along with the range of the data and showing the number of observations that fall in each bin.
Frequency count is kept on y-axis whereas intervals on x-axis. distplot() function is used to plot histograms, as shown below:
\n \n <pre class="python" style="font-family:monospace">\n \n <span style="color: #808080;font-style: italic">\n \n #Histogram\n \n sns.\n \n <span style="color: black">\n \n distplot\n \n <span style="color: black">\n \n (x\n \n <span style="color: #66cc66">\n =df \n <span style="color: black">\n [ \n <span style="color: #483d8b">\n "total_bill" \n <span style="color: black">\n ] \n <span style="color: #66cc66">\n , bins \n <span style="color: #66cc66">\n = \n <span style="color: #ff4500">\n 10 \n <span style="color: #66cc66">\n , kde \n <span style="color: #66cc66">\n = \n <span style="color: #008000">\n False \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n title \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n "Frequncy of Bill Amount" \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n xlabel \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n "Billed Amount" \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n ylabel \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n "Count" \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n show \n <span style="color: black">\n ( \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #008000"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #ff4500"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: #66cc66">\n \n </span style="color: black">\n \n </span style="color: black">\n \n </span style="color: #808080;font-style: italic">\n \n </pre class="python" style="font-family:monospace">
- bins: This parameter specifies the number of bins we want
- kde: If this parameter is set to be true, a line of kernel density estimates is plotted
We can infer that most of the customers had a bill amount between $10-15.
Heatmaps
A heatmap is a color-coded graphical representation of the magnitudes of the data elements. We can use it to determine the correlation among multiple quantitative variables.
The function used for the heatmap is heatmap(), as shown below:
\n \n <pre class="python" style="font-family:monospace">\n \n <span style="color: #808080;font-style: italic">\n \n #Heat Map\n \n sns.\n \n <span style="color: black">\n \n heatmap\n \n <span style="color: black">\n \n (df.\n \n <span style="color: black">\n corr \n <span style="color: black">\n ( \n <span style="color: black">\n ) \n <span style="color: #66cc66">\n ,cbar \n <span style="color: #66cc66">\n = \n <span style="color: #008000">\n True \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n show \n <span style="color: black">\n ( \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #008000"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black">\n \n </span style="color: black">\n \n </span style="color: black">\n \n </span style="color: #808080;font-style: italic">\n \n </pre class="python" style="font-family:monospace">
- corr(): This function correlates the quantitative variables
- colorbar: This parameter displays the color bar on the right of the heatmap when set to true
Relational Plots
Relational plots can plot scatter plot, regression plot, line plot, etc. on continuous variables. You can create plots using the relplot() function as shown:
\n \n <pre class="python" style="font-family:monospace">\n \n <span style="color: #808080;font-style: italic">\n \n #Relational Plots\n \n sns.\n \n <span style="color: black">\n \n relplot\n \n <span style="color: black">\n \n (x\n \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'total_bill' \n <span style="color: #66cc66">\n ,y \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'tip' \n <span style="color: #66cc66">\n , data \n <span style="color: #66cc66">\n = df \n <span style="color: #66cc66">\n , kind \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'scatter' \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n show \n <span style="color: black">\n ( \n <span style="color: black">\n ) \n \n sns. \n <span style="color: black">\n relplot \n <span style="color: black">\n (x \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'total_bill' \n <span style="color: #66cc66">\n ,y \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'tip' \n <span style="color: #66cc66">\n , data \n <span style="color: #66cc66">\n = df \n <span style="color: #66cc66">\n , kind \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'line' \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n show \n <span style="color: black">\n ( \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66">\n \n </span style="color: black">\n \n </span style="color: black">\n \n </span style="color: #808080;font-style: italic">\n \n </pre class="python" style="font-family:monospace">
You can also use the relplot() function to create subplots for the numerical variables against a categorical column:
\n \n <pre class="python" style="font-family:monospace">\n \n sns.\n \n <span style="color: black">\n \n relplot\n \n <span style="color: black">\n \n (x\n \n <span style="color: #66cc66">\n \n =\n \n <span style="color: #483d8b">\n 'total_bill' \n <span style="color: #66cc66">\n ,y \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'tip' \n <span style="color: #66cc66">\n , data \n <span style="color: #66cc66">\n = df \n <span style="color: #66cc66">\n , kind \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'line' \n <span style="color: #66cc66">\n , col \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'sex' \n <span style="color: #66cc66">\n , col_order \n <span style="color: #66cc66">\n = \n <span style="color: black">\n [ \n <span style="color: #483d8b">\n 'Male' \n <span style="color: #66cc66">\n , \n <span style="color: #483d8b">\n 'Female' \n <span style="color: black">\n ] \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n show \n <span style="color: black">\n ( \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b">\n \n </span style="color: #66cc66">\n \n </span style="color: black">\n \n </span style="color: black">\n \n </pre class="python" style="font-family:monospace">
Plots on Categorical Data
Strip Plots
Strip plots sort the data along with one of the axes. They are used when one of the variables under observation is categorical.
- jitter: When set to true, this parameter ensures that the data points do not overlap in the plot
The function used for the strip plot is stripplot(), as shown below:
\n \n <pre class="python" style="font-family:monospace">\n \n <span style="color: #808080;font-style: italic">\n \n #Strip Plot\n \n sns.\n \n <span style="color: black">\n \n stripplot\n \n <span style="color: black">\n \n (x\n \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'sex' \n <span style="color: #66cc66">\n ,y \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'tip' \n <span style="color: #66cc66">\n , data \n <span style="color: #66cc66">\n =df \n <span style="color: #66cc66">\n , jitter \n <span style="color: #66cc66">\n = \n <span style="color: #008000">\n True \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n show \n <span style="color: black">\n ( \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #008000"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66">\n \n </span style="color: black">\n \n </span style="color: black">\n \n </span style="color: #808080;font-style: italic">\n \n </pre class="python" style="font-family:monospace">
Swarm Plots
Swarm plots have an advantage over strip plots as here, we have don’t need to jitter the values. We use the swarmplot() function as shown below:
\n \n <pre class="python" style="font-family:monospace">\n \n <span style="color: #808080;font-style: italic">\n \n #Swarm Plot\n \n sns.\n \n <span style="color: black">\n \n swarmplot\n \n <span style="color: black">\n \n (x\n \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'sex' \n <span style="color: #66cc66">\n ,y \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'tip' \n <span style="color: #66cc66">\n , data \n <span style="color: #66cc66">\n =df \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n show \n <span style="color: black">\n ( \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66">\n \n </span style="color: black">\n \n </span style="color: black">\n \n </span style="color: #808080;font-style: italic">\n \n </pre class="python" style="font-family:monospace">
From the above plot, we can infer, men tend to tip more than women for the given data.
Bar Graphs/Plots
Bar plots are like histograms, except they show the relationship between categorical and continuous variables. The data is displayed using rectangular bars, where the length of the bar represents the proportion of the data in that category.
We use the barplot() function as shown below:
\n \n <pre class="python" style="font-family:monospace">\n \n <span style="color: #808080;font-style: italic">\n \n #Bar Plot\n \n sns.\n \n <span style="color: black">\n \n barplot\n \n <span style="color: black">\n \n (x\n \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'smoker' \n <span style="color: #66cc66">\n ,y \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'total_bill' \n <span style="color: #66cc66">\n , data \n <span style="color: #66cc66">\n =df \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n show \n <span style="color: black">\n ( \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66">\n \n </span style="color: black">\n \n </span style="color: black">\n \n </span style="color: #808080;font-style: italic">\n \n </pre class="python" style="font-family:monospace">
These graphs represent the estimate of central tendency.
- ci: This parameter is the Confidence Interval and setting it to none will disable the displayed line through the bars
\n \n <pre class="python" style="font-family:monospace">\n \n <span style="color: #808080;font-style: italic">\n \n #Bar Plot\n \n sns.\n \n <span style="color: black">\n \n barplot\n \n <span style="color: black">\n \n (x\n \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'smoker' \n <span style="color: #66cc66">\n ,y \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'total_bill' \n <span style="color: #66cc66">\n , data \n <span style="color: #66cc66">\n =df \n <span style="color: #66cc66">\n , ci \n <span style="color: #66cc66">\n = \n <span style="color: #008000">\n None \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n show \n <span style="color: black">\n ( \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #008000"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66">\n \n </span style="color: black">\n \n </span style="color: black">\n \n </span style="color: #808080;font-style: italic">\n \n </pre class="python" style="font-family:monospace">
Thus, we can infer, smokers tend to eat more and hence, pay a higher bills.
Point Plots
Point plots are like line plots, except they display a categorical variable on the x-axis. They are just different styles of bar plots. Rather than a rectangular bar, the data points are represented by the point at a certain height on the other axis.
We use the pointplot() function as shown below:
\n \n <pre class="python" style="font-family:monospace">\n \n <span style="color: #808080;font-style: italic">\n \n #Point Plot\n \n sns.\n \n <span style="color: black">\n \n pointplot\n \n <span style="color: black">\n \n (x\n \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'smoker' \n <span style="color: #66cc66">\n ,y \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'total_bill' \n <span style="color: #66cc66">\n , data \n <span style="color: #66cc66">\n =df \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n show \n <span style="color: black">\n ( \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66">\n \n </span style="color: black">\n \n </span style="color: black">\n \n </span style="color: #808080;font-style: italic">\n \n </pre class="python" style="font-family:monospace">
Count Plots
Count plots are like bar plots, but they show the no of observations in each category rather than computing a statistic for a second variable.
We use the countplot() function as shown below to show the count of smokers and non-smokers:
\n \n <pre class="python" style="font-family:monospace">\n \n <span style="color: #808080;font-style: italic">\n \n #Count Plot\n \n sns.\n \n <span style="color: black">\n \n countplot\n \n <span style="color: black">\n \n (x\n \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'smoker' \n <span style="color: #66cc66">\n , data \n <span style="color: #66cc66">\n =df \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n show \n <span style="color: black">\n ( \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66">\n \n </span style="color: black">\n \n </span style="color: black">\n \n </span style="color: #808080;font-style: italic">\n \n </pre class="python" style="font-family:monospace">
Boxplots
A boxplot is used to display data distribution through quartiles. Quartiles (Q1, Q2, Q3, Q4) are basically the division of data into four equal groups or intervals. A median separates the lower half and upper half of the data. The lines extending from the box are known as whiskers.
Boxplots are used to detect outliers in data and how tightly the data is grouped. The function used for the box plot is boxplot().
Let’s analyze how the tipped amount varies during lunch and dinner time and if there are any outliers in our data:
\n \n <pre class="python" style="font-family:monospace">\n \n <span style="color: #808080;font-style: italic">\n \n #Box Plot\n \n sns.\n \n <span style="color: black">\n \n boxplot\n \n <span style="color: black">\n \n (x\n \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'time' \n <span style="color: #66cc66">\n ,y \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'tip' \n <span style="color: #66cc66">\n , data \n <span style="color: #66cc66">\n =df \n <span style="color: #66cc66">\n , whis \n <span style="color: #66cc66">\n = \n <span style="color: #ff4500">\n 1 \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n show \n <span style="color: black">\n ( \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #ff4500"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66">\n \n </span style="color: black">\n \n </span style="color: black">\n \n </span style="color: #808080;font-style: italic">\n \n </pre class="python" style="font-family:monospace">
Categorical Plots
These plots are relational plots but for categorical plots to form subplots. You can create plots using the catplot() function as shown:
\n \n <pre class="python" style="font-family:monospace">\n \n <span style="color: #808080;font-style: italic">\n \n #Cat Plots\n \n sns.\n \n <span style="color: black">\n \n catplot\n \n <span style="color: black">\n \n (x\n \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'total_bill' \n <span style="color: #66cc66">\n , data \n <span style="color: #66cc66">\n =df \n <span style="color: #66cc66">\n , kind \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'bar' \n <span style="color: #66cc66">\n , col \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'smoker' \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n show \n <span style="color: black">\n ( \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66">\n \n </span style="color: black">\n \n </span style="color: black">\n \n </span style="color: #808080;font-style: italic">\n \n </pre class="python" style="font-family:monospace">
Creating Multiplot Grids for Data Visualization using Seaborn
Seaborn allows you to plot multiple grids (plots) side-by-side to aid comparison between them.
Consider the following example of facetgrid() function:
\n \n <pre class="python" style="font-family:monospace">\n \n <span style="color: #808080;font-style: italic">\n \n #Load the titanic dataset under Seaborn \n \n titanic \n \n <span style="color: #66cc66">\n \n = sns.\n \n <span style="color: black">\n \n load_dataset\n \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n 'titanic' \n <span style="color: black">\n ) \n \n \n <span style="color: #808080;font-style: italic">\n #facetgrid() function \n df_grid \n <span style="color: #66cc66">\n = sns. \n <span style="color: black">\n FacetGrid \n <span style="color: black">\n (titanic \n <span style="color: #66cc66">\n , col \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n "embark_town" \n <span style="color: black">\n ) \n df_grid. \n <span style="color: #008000">\n map \n <span style="color: black">\n (plt. \n <span style="color: black">\n hist \n <span style="color: #66cc66">\n , \n <span style="color: #483d8b">\n "fare" \n <span style="color: black">\n ) \n <span style="color: #66cc66">\n ; \n </span style="color: #66cc66"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #008000"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: #808080;font-style: italic"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: black">\n \n </span style="color: black">\n \n </span style="color: #66cc66">\n \n </span style="color: #808080;font-style: italic">\n \n </pre class="python" style="font-family:monospace">
The above output shows the comparison between fares when a passenger embarks from a given town.
You can also plot using the PairGrid() function when you have a pair of variables to compare. Consider the following example:
\n \n <pre class="python" style="font-family:monospace">\n \n <span style="color: #808080;font-style: italic">\n \n #Load the flight dataset under Seaborn \n \n flights \n \n <span style="color: #66cc66">\n \n = sns.\n \n <span style="color: black">\n \n load_dataset\n \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n 'flights' \n <span style="color: black">\n ) \n \n \n <span style="color: #808080;font-style: italic">\n #PairGrid() function \n df2_grid \n <span style="color: #66cc66">\n = sns. \n <span style="color: black">\n PairGrid \n <span style="color: black">\n (flights \n <span style="color: black">\n ) \n df2_grid. \n <span style="color: #008000">\n map \n <span style="color: black">\n (plt. \n <span style="color: black">\n scatter \n <span style="color: black">\n ) \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #008000"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: #808080;font-style: italic"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: black">\n \n </span style="color: black">\n \n </span style="color: #66cc66">\n \n </span style="color: #808080;font-style: italic">\n \n </pre class="python" style="font-family:monospace">
The above output displays a grid of comparison between the years and the number of passengers.
Customizing Seaborn Plots
Hue Parameter – Adding a third variable to categorize the plots
- The hue parameter is used to categorize data points based on the third variable
- The hue_order parameter is used to order the third variable in the plot
- The palette parameter sets the color of the points for each variable
\n \n <pre class="python" style="font-family:monospace">\n \n <span style="color: #808080;font-style: italic">\n \n #Adding a third variable to categorize plots\n \n hue_colors \n \n <span style="color: #66cc66">\n \n =sns.\n \n <span style="color: black">\n \n color_palette(\n \n <span style="color: #483d8b">\n 'Greens' \n <span style="color: #66cc66">\n , \n <span style="color: #ff4500">\n 7 \n <span style="color: black">\n ) \n sns. \n <span style="color: black">\n countplot(x \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n "smoker" \n <span style="color: #66cc66">\n , data \n <span style="color: #66cc66">\n =df \n <span style="color: #66cc66">\n , hue \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'tip' \n <span style="color: #66cc66">\n ,hue_order \n <span style="color: #66cc66">\n = \n <span style="color: black">\n [ \n <span style="color: #ff4500">\n 1 \n <span style="color: #66cc66">\n , \n <span style="color: #ff4500">\n 2 \n <span style="color: #66cc66">\n , \n <span style="color: #ff4500">\n 3 \n <span style="color: #66cc66">\n , \n <span style="color: #ff4500">\n 4 \n <span style="color: #66cc66">\n , \n <span style="color: #ff4500">\n 5 \n <span style="color: #66cc66">\n , \n <span style="color: #ff4500">\n 6 \n <span style="color: #66cc66">\n , \n <span style="color: #ff4500">\n 10 \n <span style="color: black">\n ] \n <span style="color: #66cc66">\n ,palette \n <span style="color: #66cc66">\n =hue_colors \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n xlabel( \n <span style="color: #483d8b">\n "Smoker" \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n ylabel( \n <span style="color: #483d8b">\n "Count" \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n title( \n <span style="color: #483d8b">\n "The count of Smokers" \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n xticks(rotation \n <span style="color: #66cc66">\n = \n <span style="color: #ff4500">\n 270 \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n show() \n \n hue_colors2 \n <span style="color: #66cc66">\n = sns. \n <span style="color: black">\n color_palette( \n <span style="color: #483d8b">\n "Paired" \n <span style="color: black">\n ) \n sns. \n <span style="color: black">\n scatterplot(x \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'passengers' \n <span style="color: #66cc66">\n ,y \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'year' \n <span style="color: #66cc66">\n , data \n <span style="color: #66cc66">\n =flights \n <span style="color: #66cc66">\n , hue \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'month' \n <span style="color: #66cc66">\n , palette \n <span style="color: #66cc66">\n =hue_colors2 \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n title( \n <span style="color: #483d8b">\n "Flight Passengers" \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n show() \n \n iris \n <span style="color: #66cc66">\n = sns. \n <span style="color: black">\n load_dataset( \n <span style="color: #483d8b">\n 'iris' \n <span style="color: black">\n ) \n sns. \n <span style="color: black">\n lineplot(x \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'sepal_length' \n <span style="color: #66cc66">\n ,y \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'sepal_width' \n <span style="color: #66cc66">\n , data \n <span style="color: #66cc66">\n =iris \n <span style="color: #66cc66">\n ,hue \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'species' \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n title( \n <span style="color: #483d8b">\n "Sepals Length and Width of Flowers" \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n show() \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #ff4500"> \n </span style="color: #66cc66"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #483d8b"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: black"> \n </span style="color: #ff4500"> \n </span style="color: #66cc66"> \n </span style="color: #ff4500"> \n </span style="color: #66cc66"> \n </span style="color: #ff4500"> \n </span style="color: #66cc66"> \n </span style="color: #ff4500"> \n </span style="color: #66cc66"> \n </span style="color: #ff4500"> \n </span style="color: #66cc66"> \n </span style="color: #ff4500"> \n </span style="color: #66cc66"> \n </span style="color: #ff4500"> \n </span style="color: black"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b"> \n </span style="color: #66cc66"> \n </span style="color: black"> \n </span style="color: black"> \n </span style="color: #ff4500"> \n </span style="color: #66cc66"> \n </span style="color: #483d8b">\n \n </span style="color: black">\n \n </span style="color: #66cc66">\n \n </span style="color: #808080;font-style: italic">\n \n </pre class="python" style="font-family:monospace">
Background Styles
- set_style(): This function can set the background to the following:
(‘white’,’dark’,’whitegrid’,’darkgrid’,’ticks’)
\n \n <pre class="python" style="font-family:monospace">\n \n <span style="color: #808080;font-style: italic">\n \n #Setting the background style\n \n sns.\n \n <span style="color: black">\n \n set_style\n \n <span style="color: black">\n \n (\n \n <span style="color: #483d8b">\n 'dark' \n <span style="color: black">\n ) \n sns. \n <span style="color: black">\n countplot \n <span style="color: black">\n (x \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n "smoker" \n <span style="color: #66cc66">\n , data \n <span style="color: #66cc66">\n =df \n <span style="color: #66cc66">\n , hue \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'tip' \n <span style="color: #66cc66">\n ,hue_order \n <span style="color: #66cc66">\n = \n <span style="color: black">\n [ \n <span style="color: #ff4500">\n 1 \n <span style="color: #66cc66">\n , \n <span style="color: #ff4500">\n 2 \n <span style="color: #66cc66">\n , \n <span style="color: #ff4500">\n 3 \n <span style="color: #66cc66">\n , \n <span style="color: #ff4500">\n 4 \n <span style="color: #66cc66">\n , \n <span style="color: #ff4500">\n 5 \n <span style="color: #66cc66">\n , \n <span style="color: #ff4500">\n 6 \n <span style="color: #66cc66">\n , \n <span style="color: #ff4500">\n 10 \n <span style="color: black">\n ] \n <span style="color: #66cc66">\n ,palette \n <span style="color: #66cc66">\n =hue_colors \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n xlabel \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n "Smoker" \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n ylabel \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n "Count" \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n title \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n "The count of Smokers" \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n xticks \n <span style="color: black">\n (rotation \n <span style="color: #66cc66">\n = \n <span style="color: #ff4500">\n 270 \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n show \n <span style="color: black">\n ( \n <span style="color: black">\n ) \n \n sns. \n <span style="color: black">\n set_style \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n 'whitegrid' \n <span style="color: black">\n ) \n hue_colors2 \n <span style="color: #66cc66">\n = sns. \n <span style="color: black">\n color_palette \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n "Paired" \n <span style="color: black">\n ) \n sns. \n <span style="color: black">\n scatterplot \n <span style="color: black">\n (x \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'passengers' \n <span style="color: #66cc66">\n ,y \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'year' \n <span style="color: #66cc66">\n , data \n <span style="color: #66cc66">\n =flights \n <span style="color: #66cc66">\n , hue \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'month' \n <span style="color: #66cc66">\n , palette \n <span style="color: #66cc66">\n =hue_colors2 \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n title \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n "Flight Passengers" \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n show \n <span style="color: black">\n ( \n <span style="color: black">\n ) \n \n sns. \n <span style="color: black">\n set_style \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n 'darkgrid' \n <span style="color: black">\n ) \n iris \n <span style="color: #66cc66">\n = sns. \n <span style="color: black">\n load_dataset \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n 'iris' \n <span style="color: black">\n ) \n sns. \n <span style="color: black">\n lineplot \n <span style="color: black">\n (x \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'sepal_length' \n <span style="color: #66cc66">\n ,y \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'sepal_width' \n <span style="color: #66cc66">\n , data \n <span style="color: #66cc66">\n =iris \n <span style="color: #66cc66">\n ,hue \n <span style="color: #66cc66">\n = \n <span style="color: #483d8b">\n 'species' \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n title \n <span style="color: black">\n ( \n <span style="color: #483d8b">\n "Sepals Length and Width of Flowers" \n <span style="color: black">\n ) \n plt. \n <span style="color: black">\n show \n <span style="color: black">\n ( \n <span style="color: black">\n ) \n <div class="photo-widget-full"> \n <div class="figure"> \n <picture> \n <source srcset="https://images.shiksha.com/mediadata/ugcDocuments/images/wordpressImages/2022_02_Customizing-Seaborn-Plots_480x360.jpg" media="(max-width: 500px)"> \n <img src="https://images.shiksha.com/mediadata/ugcDocuments/images/wordpressImages/2022_02_Customizing-Seaborn-Plots.jpg" alt="2022_02_Customizing-Seaborn-Plots.jpg" width="390" height="282"> \n </picture> \n </div> \n </div> \n <div class="photo-widget-full"> \n <div class="figure"> \n <picture> \n <source srcset="https://images.shiksha.com/mediadata/ugcDocuments/images/wordpressImages/2022_02_set_style-2_480x360.jpg" media="(max-width: 500px)"> \n <img src="https://images.shiksha.com/mediadata/ugcDocuments/images/wordpressImages/2022_02_set_style-2.jpg" alt="2022_02_set_style-2.jpg" width="394" height="274"> \n </picture> \n </div> \n </div> \n <div class="photo-widget-full"> \n <div class="figure"> \n <picture> \n <source srcset="https://images.shiksha.com/mediadata/ugcDocuments/images/wordpressImages/2022_02_set_style-3_480x360.jpg" media="(max-width: 500px)"> \n <img src="https://images.shiksha.com/mediadata/ugcDocuments/images/wordpressImages/2022_02_set_style-3.jpg" alt="2022_02_set_style-3.jpg" width="387" height="281"> \n </picture> \n </div> \n </div> \n <p><strong>Color Palettes</strong></p> \n <p>Let’s take a look at the colors currently present within Seaborn using the <strong>paltplot()</strong> function:</p> \n
We have shown how to use the color_palette() function in the customization examples above.
Data Visualization using Seaborn Demo – Try it Yourself
Click the google colab icon below to run and practice the demo.
This is a collection of insightful articles from domain experts in the fields of Cloud Computing, DevOps, AWS, Data Science, Machine Learning, AI, and Natural Language Processing. The range of topics caters to upski... Read Full Bio