{"id":2755,"date":"2019-08-19T05:55:05","date_gmt":"2019-08-19T05:55:05","guid":{"rendered":"https:\/\/prwatech.in\/blog\/?p=2755"},"modified":"2020-07-10T05:16:24","modified_gmt":"2020-07-10T05:16:24","slug":"seaborn-data-visualising-library-in-python","status":"publish","type":"post","link":"https:\/\/prwatech.in\/blog\/python\/seaborn-data-visualising-library-in-python\/","title":{"rendered":"Seaborn Library for Data Visualization in Python"},"content":{"rendered":"<p>&nbsp;<\/p>\n<h1 class=\"LC20lb\"><span class=\"S3Uucc\">Seaborn Library for Data Visualization in Python<\/span><\/h1>\n<p>&nbsp;<\/p>\n<p>Seaborn Library for Data Visualization in Python, welcome to the world of\u00a0 Python data visualization using seaborn. Are you the one who is looking forward to knowing the Seaborn Library for Data Visualization in Python? Or the one who is very keen to explore the Seaborn Library for Data Visualization in Python with examples that are available? Then you\u2019ve landed on the Right path which provides the standard information of <a href=\"https:\/\/prwatech.in\/python-training-institute-in-bangalore\/\" title=\"online training courses for python\">Python Programming language.<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Seaborn library is a data visualization library based on matplotlib in Python. It provides a high-level interface for drawing attractive and informative statistical graphics.Do you want to know about data visualization in python using seaborn, then just follow the below mentioned Python Data Visualisation using Seaborn tutorial for Beginners from <a href=\"https:\/\/prwatech.com\/\" title=\"online python training course\">Prwatech<\/a> and take advanced <a href=\"https:\/\/prwatech.in\/python-training-institute-in-bangalore\/\" title=\"online python programming course\">Python training<\/a> like a Pro from today itself under 10+ years of hands-on experienced Professionals.<\/p>\n<p>&nbsp;<\/p>\n<h2>Python Data Visualisation using Seaborn<\/h2>\n<p>&nbsp;<\/p>\n<p>1. In the world of Analytics, the best way to get insight details is by visualizing the dataset.<br \/>\n2. Datasets can be visualized by displaying it as plots that are easy to understand and explore. Such data helps in drawing the attention of key elements.<br \/>\n3. In order to analyze a set of data using Python, we use Matplotlib, a widely implemented 2D plotting library.<br \/>\n4. Similarly, Seaborn is a visualization library in Python.<br \/>\n5. It is built on top of Matplotlib.<\/p>\n<p>&nbsp;<\/p>\n<h2>Difference between Matplotlib and Seaborn<\/h2>\n<p>&nbsp;<\/p>\n<p>Seaborn helps resolve the two major problems faced by Matplotlib; the problems are<\/p>\n<p>1. Default Matplotlib parameters<br \/>\n2. Working with data frames<br \/>\n3. As Seaborn compliments and extends Matplotlib, the learning curve is quite gradual. If you know Matplotlib, you are already halfway through Seaborn.<\/p>\n<p>&nbsp;<\/p>\n<h3>Important Features of Seaborn<\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Seaborn is built over Python\u2019s core visualization library Matplotlib.\u00a0<\/span><span style=\"font-weight: 400;\">It is used to serve as a compliment and not a replacement.\u00a0<\/span><span style=\"font-weight: 400;\">Although, Seaborn comes with some very important features.\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Let us see a few of them here. The features helps in<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">1. It is a built-in theme for styling matplotlib graphics<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. Visualizing univariate and bivariate data<\/span><\/p>\n<p><span style=\"font-weight: 400;\">3. Fitting in and visualizing linear regression models<\/span><\/p>\n<p><span style=\"font-weight: 400;\">4. Plotting statistical time-series data<\/span><\/p>\n<p><span style=\"font-weight: 400;\">5. Seaborn works better with NumPy and Pandas data structures<\/span><\/p>\n<p><span style=\"font-weight: 400;\">6. In most cases, you will still use Matplotlib for simple plotting. The knowledge of Matplotlib is recommended to use Seaborn\u2019s default plots.<\/span><\/p>\n<p>7. Installing Seaborn and getting started<\/p>\n<p><span style=\"font-weight: 400;\">8. Using Pip Installer<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2>Installation of Seaborn<\/h2>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">To install the latest release of Seaborn, you can use pip:<\/span><\/p>\n<p><b>Syntax)<\/b><span style=\"font-weight: 400;\"> pip install seaborn<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><b>For Windows, Linux &amp; Mac using Anaconda<\/b><\/h3>\n<p>&nbsp;<\/p>\n<h3><b>Dependencies<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">1.Python 2.7 or 3.4+<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. numpy<\/span><\/p>\n<p><span style=\"font-weight: 400;\">3. scipy<\/span><\/p>\n<p><span style=\"font-weight: 400;\">4. pandas<\/span><\/p>\n<p><span style=\"font-weight: 400;\">5. matplotlib<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><b>Importing Libraries<\/b><\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u00a01. import pandas as pd<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. from matplotlib import pyplot as plt<\/span><\/p>\n<p><span style=\"font-weight: 400;\">3. import seaborn as sb<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><b>Importing Datasets<\/b><\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u00a01. Seaborn comes with a few important datasets in its library.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. When Seaborn is installed, datasets download automatically<\/span><b>.<\/b><\/p>\n<p><span style=\"font-weight: 400;\">3. Loading DataSet:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">4. load_dataset()<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><b>Importing Data as Pandas DataFrame<\/b><\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u00a01. import seaborn as sb<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. df = sb.load_dataset(&#8216;tickets&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400;\">3. print df.head()<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3>Seaborn &#8211; Figure Aesthetic<\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u00a01. Aesthetics is a set of principles concerned with nature and appreciation of beauty, especially in art. Visualization is an art of representing data in an effective and easiest possible way.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. Seaborn comes with customized themes and a high-level interface to customize and control the look of Matplotlib graphs.<\/span><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">numpy <\/span><b>as <\/b><span style=\"font-weight: 400;\">np<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>def <\/b><span style=\"font-weight: 400;\">sinplot(flip = <\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">):<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">x = np.linspace(<\/span><span style=\"font-weight: 400;\">0<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">4<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">400<\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>for <\/b><span style=\"font-weight: 400;\">i <\/span><b>in <\/b><span style=\"font-weight: 400;\">range<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">4<\/span><span style=\"font-weight: 400;\">):<\/span><\/p>\n<p><span style=\"font-weight: 400;\">plt.plot(x, np.sin(x + i * <\/span><span style=\"font-weight: 400;\">.6<\/span><span style=\"font-weight: 400;\">) * (<\/span><span style=\"font-weight: 400;\">8 <\/span><span style=\"font-weight: 400;\">&#8211; i) * flip)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sinplot()<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><strong>Output()<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-2756\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/sea.png\" alt=\"Seaborn Library for Data Visualization in Python\" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/sea.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/sea-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3><strong>Using set() functions<\/strong><\/h3>\n<p>&nbsp;<\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">numpy <\/span><b>as <\/b><span style=\"font-weight: 400;\">np<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>def <\/b><span style=\"font-weight: 400;\">sinplot(flip = <\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">):<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">x = np.linspace(<\/span><span style=\"font-weight: 400;\">0<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">4<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">400<\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>for <\/b><span style=\"font-weight: 400;\">i <\/span><b>in <\/b><span style=\"font-weight: 400;\">range<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">4<\/span><span style=\"font-weight: 400;\">):<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.plot(x, np.sin(x + i * <\/span><span style=\"font-weight: 400;\">.6<\/span><span style=\"font-weight: 400;\">) * (<\/span><span style=\"font-weight: 400;\">8 <\/span><span style=\"font-weight: 400;\">&#8211; i) * flip)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.set()<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sinplot()<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><b>Output:<\/b><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-2757\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/set.png\" alt=\"Seaborn Library for Data Visualization in Python\" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/set.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/set-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">The above two figures show the difference in default Matplotlib and Seaborn plots. The representation of the dataset is the same, but the representation style differs in both.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Basically, Seaborn splits the Matplotlib parameters into two groups\u2212<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a01. Plot styles<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. Plot scale<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><b>Seaborn Figure Styles<\/b><\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u00a01. The interface to manipulate the styles is set_style().\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. Using this function you can set the theme of the plot.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">3. As per the latest updated version, below are five themes available.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 Darkgrid<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 Whitegrid<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 Dark<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 White<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 Ticks<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 Using Darkgrip<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">numpy <\/span><b>as <\/b><span style=\"font-weight: 400;\">np<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>def <\/b><span style=\"font-weight: 400;\">sinplot(flip=<\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">):<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">x = np.linspace(<\/span><span style=\"font-weight: 400;\">0<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">4<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">400<\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>for <\/b><span style=\"font-weight: 400;\">i <\/span><b>in <\/b><span style=\"font-weight: 400;\">range<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">4<\/span><span style=\"font-weight: 400;\">):<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.plot(x, np.sin(x + i * <\/span><span style=\"font-weight: 400;\">.6<\/span><span style=\"font-weight: 400;\">) * (<\/span><span style=\"font-weight: 400;\">8 <\/span><span style=\"font-weight: 400;\">&#8211; i) * flip)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.set_style(<\/span><b>&#8220;darkgrid&#8221;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sinplot()<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><b>Overriding the Elements<\/b><\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u00a01. If you need to customize the Seaborn styles, you can pass a dictionary of parameters to set_style() function.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. Parameters available are viewed using axes_style() function<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><b>Scaling Plot Elements<\/b><\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">We also have control of plot elements and can control the scale of the plot using set_context() function.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We have four preset templates for contexts, based on relative size, the contexts are named as follows<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a01. Paper<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. Notebook<\/span><\/p>\n<p><span style=\"font-weight: 400;\">3. Talk<\/span><\/p>\n<p><span style=\"font-weight: 400;\">4. Poster<\/span><\/p>\n<p><span style=\"font-weight: 400;\">By default, context is set to notebook; and was used in the plots above.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><b>Seaborn &#8211;<\/b> Color<b> Palette<\/b><\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u00a01. Color plays an indeed important role than any other aspect when it comes to visualizations.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. When used effectively, color can add more value to a plot.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">3. A palette is a flat surface on which a painter arranges and mixes paints together.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><b>Building Color Palette:<\/b><\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u00a01. Seaborn has a function called color_palette(), which is used to give colors to plots and adding more aesthetic value to it.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. Syntax)<\/span> <span style=\"font-weight: 400;\">seaborn.color_palette(palette = None, n_colors = None, desat = No<\/span><\/p>\n<p><b>Parameter<\/b><\/p>\n<p>&nbsp;<\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400;\">Name<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Description\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">n_colors<\/span><\/td>\n<td><span style=\"font-weight: 400;\">A number of colors in the palette.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If None, then the default depends on how the palette is specified.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">By default, the value of n_colors in 6 colors.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">desat<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Proportion to desaturate each color.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<h3><strong>Return<\/strong><\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Return refers to the list of RGB tuples. Following are the readily available Seaborn palettes:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a01. Deep<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a02.Muted<\/span><\/p>\n<p><span style=\"font-weight: 400;\">3. Bright<\/span><\/p>\n<p><span style=\"font-weight: 400;\">4. Pastel<\/span><\/p>\n<p><span style=\"font-weight: 400;\">5. Dark<\/span><\/p>\n<p><span style=\"font-weight: 400;\">6. Colorblind<\/span><\/p>\n<p><span style=\"font-weight: 400;\">It is difficult to decide which palette should be used for a given data set without actually knowing the characteristics of data. Being aware of it, we will classify the different ways of using color_palette() types:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a01. qualitative<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. sequential<\/span><\/p>\n<p><span style=\"font-weight: 400;\">3. diverging<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We have a function seaborn.palplot() which deals with color palettes.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">It plots the color palette as a horizontal array.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Qualitative or categorical palettes are best suitable to plot the categorical data.<\/span><\/p>\n<p><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">current_palette = sb.color_palette()<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.palplot(current_palette)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2758\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/colorpallets.png\" alt=\"Seaborn Library for Data Visualization in Python\" width=\"850\" height=\"85\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/colorpallets.png 1000w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/colorpallets-300x30.png 300w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/colorpallets-768x77.png 768w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3><b>Sequential<\/b> Color<b> Palettes<\/b><\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">The sequential plot is suitable to express the distribution of data ranging from relatively lower values to higher values within a range.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Appending an additional character \u2018s\u2019 to the color passed to the color parameter will plot the Sequential plot.<\/span><\/p>\n<p><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">current_palette = sb.color_palette()<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.palplot(sb.color_palette(<\/span><b>&#8220;Reds&#8221;<\/b><span style=\"font-weight: 400;\">))<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><strong>Output<\/strong>()<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2759\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/red.png\" alt=\"Seaborn Library for Data Visualization in Python\" width=\"850\" height=\"142\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/red.png 600w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/red-300x50.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3><b>Diverging<\/b> Color<b> Palette<\/b><\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u00a01. Diverging palettes uses two different colors.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. Each color represents variation in value ranging from common points in either direction.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">3. Assume plotting data ranging from -2 to 2. The values from -2 to 0 will take one color and 0 to +1 will take another color.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">4. By default, the values are centered from 0. You can control it with parameter center by passing a value.<\/span><\/p>\n<p><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">current_palette = sb.color_palette()<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.palplot(sb.color_palette(<\/span><b>&#8220;BrBG&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">9<\/span><span style=\"font-weight: 400;\">))<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2760\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/twocolor.png\" alt=\"Seaborn Library for Data Visualization in Python\" width=\"850\" height=\"94\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/twocolor.png 900w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/twocolor-300x33.png 300w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/twocolor-768x85.png 768w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3><b>Setting the<\/b> Default<b> Color Palette<\/b><\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u00a01. The functions color_palette() have a companion called set_palette().<\/span><\/p>\n<p><span style=\"font-weight: 400;\">2. The relationship between them is similar to pairs covered in the aesthetics chapter.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">3. The arguments are same for both set_palette() and color_palette(), but the default Matplotlib parameters changed so that the palette is used for all plots.<\/span><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">numpy <\/span><b>as <\/b><span style=\"font-weight: 400;\">np<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>def <\/b><span style=\"font-weight: 400;\">sinplot(flip = <\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">):<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">x = np.linspace(<\/span><span style=\"font-weight: 400;\">0<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">4<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">400<\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>for <\/b><span style=\"font-weight: 400;\">i <\/span><b>in <\/b><span style=\"font-weight: 400;\">range<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">4<\/span><span style=\"font-weight: 400;\">):<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.plot(x, np.sin(x + i * <\/span><span style=\"font-weight: 400;\">.6<\/span><span style=\"font-weight: 400;\">) * (<\/span><span style=\"font-weight: 400;\">8 <\/span><span style=\"font-weight: 400;\">&#8211; i) * flip)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.set_style(<\/span><b>&#8220;white&#8221;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.set_palette(<\/span><b>&#8220;husl&#8221;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sinplot()<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2796\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/defaultcolor.png\" alt=\"Seaborn Library for Data Visualization in Python\" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/defaultcolor.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/defaultcolor-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3><b>Plotting<\/b> Univariate<b> Distribution<\/b><\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">The distribution of data is the foremost thing that we are supposed to understand while analyzing the data. Here, we will see how seaborn helps us in understanding the univariate distribution of the data.<\/span><\/p>\n<p><strong>Syntax) seaborn.distplot()<\/strong><\/p>\n<p><b>Parameters:<\/b><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Name<\/b><\/td>\n<td><b>Description<\/b><\/td>\n<\/tr>\n<tr>\n<td><b>data<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Series, 1d array or a list<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>bins<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Specification of hist bins<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>hist<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Bool<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>kde<\/b><\/td>\n<td><span style=\"font-weight: 400;\">Bool<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<h2><b>Seaborn<\/b><b> &#8211; Histogram<\/b><\/h2>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Histograms represent data distribution by forming bins along with the range of the data and then drawing bars to show the number of observations that fall in each bin.<\/span><br \/>\n<b>import <\/b><span style=\"font-weight: 400;\">pandas <\/span><b>as <\/b><span style=\"font-weight: 400;\">pd<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;iris&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.distplot(df[<\/span><b>&#8216;petal_length&#8217;<\/b><span style=\"font-weight: 400;\">],<\/span><span style=\"font-weight: 400;\">kde <\/span><span style=\"font-weight: 400;\">= <\/span><b>False<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2762\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/bar-1.png\" alt=\"Seaborn Library for Data Visualization in Python\" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/bar-1.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/bar-1-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Here, kde flag is set as False. Therefore, the representation of the kernel estimation plot is removed and the only histogram is plotted.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3>Kernel Density Estimates<\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Kernel Density Estimation (KDE) is used to estimate the probability density function (PDF) of a continuous random variable. It is used in the non-parametric analysis.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Setting up the hist flag to False value in a distplot will yield the kernel density estimation plot.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Ex)<\/span> <b>import <\/b><span style=\"font-weight: 400;\">pandas <\/span><b>as <\/b><span style=\"font-weight: 400;\">pd<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;iris&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.distplot(df[<\/span><b>&#8216;petal_length&#8217;<\/b><span style=\"font-weight: 400;\">],<\/span><span style=\"font-weight: 400;\">hist<\/span><span style=\"font-weight: 400;\">=<\/span><b>False<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><strong>OutPut()<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2763\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/kde.png\" alt=\"Seaborn Library for Data Visualization in Python\" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/kde.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/kde-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3><b>Fitting Parametric<\/b> Distribution<\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">distplot() is used to visualize the parametric distribution of a dataset.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Ex)<\/span> <b>import <\/b><span style=\"font-weight: 400;\">pandas <\/span><b>as <\/b><span style=\"font-weight: 400;\">pd<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;iris&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.distplot(df[<\/span><b>&#8216;petal_length&#8217;<\/b><span style=\"font-weight: 400;\">])<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><strong>Output()<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2764\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/fpd.png\" alt=\"Seaborn Library for Data Visualization in Python\" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/fpd.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/fpd-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><\/h3>\n<h3><b>Plotting Bivariate<\/b> Distribution<\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Bivariate Distribution is used to identify the relation between the two variables. This mainly deals with how one variable is behaving with respect to the other.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The best way to analyze Bivariate Distribution in seaborn is by using a jointplot() function.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Jointplot creates a multi-panel figure which projects bivariate relationship between two variables and univariate distribution of each variable on separate axes.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><b>Scatter<\/b> Plot<\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Scatter plot is most convenient way to display distribution where each observation is represented in a two-dimensional plot via x and y axis.<\/span><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">pandas <\/span><b>as <\/b><span style=\"font-weight: 400;\">pd<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;iris&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.jointplot(<\/span><span style=\"font-weight: 400;\">x <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8216;petal_length&#8217;<\/b><span style=\"font-weight: 400;\">,<\/span><span style=\"font-weight: 400;\">y <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8216;petal_width&#8217;<\/b><span style=\"font-weight: 400;\">,<\/span><span style=\"font-weight: 400;\">data <\/span><span style=\"font-weight: 400;\">= df)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2765\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/scatterplot-1024x503.png\" alt=\"Python Seaborn Tutorial \" width=\"850\" height=\"418\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/scatterplot-1024x503.png 1024w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/scatterplot-300x147.png 300w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/scatterplot-768x377.png 768w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/scatterplot-1200x589.png 1200w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/scatterplot.png 1366w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">A trend in the plot displays a positive correlation exists between variables under study.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><b>Hexbin<\/b> Plot<\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Hexagonal binning is used in a bivariate data analysis when the dataset is sparse in density, which means when data is very scattered and difficult to analyze through scatterplots.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">An addition parameter called \u2018kind\u2019 and value \u2018hex\u2019 plots a hexbin plot.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Ex)<\/span> <b>import <\/b><span style=\"font-weight: 400;\">pandas <\/span><b>as <\/b><span style=\"font-weight: 400;\">pd<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;iris&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.jointplot(<\/span><span style=\"font-weight: 400;\">x <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8216;petal_length&#8217;<\/b><span style=\"font-weight: 400;\">,<\/span><span style=\"font-weight: 400;\">y <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8216;petal_width&#8217;<\/b><span style=\"font-weight: 400;\">,<\/span><span style=\"font-weight: 400;\">data <\/span><span style=\"font-weight: 400;\">= df,<\/span><span style=\"font-weight: 400;\">kind <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8216;hex&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><strong>Output()<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2766\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/hexabin.png\" alt=\"Python Seaborn Tutorial \" width=\"850\" height=\"850\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/hexabin.png 600w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/hexabin-150x150.png 150w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/hexabin-300x300.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2><b>Seaborn<\/b> &#8211;<b> Visualizing Pairwise Relationship<\/b><\/h2>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Data under real-time study contain many variables. In such cases, the relation between each and every variable should be analyzed. Plotting Bivariate Distribution of (n,2) combinations will be a very complicated and time taking process.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In order to plot multiple pairwise bivariate distributions in a dataset, you may use the pairplot() function.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This shows the relationship for (n,2) a combination of the variable in a DataFrame as a matrix of plots and diagonal plots are the univariate plots.<\/span><\/p>\n<p><strong>Parameters<\/strong><\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400;\">Name<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Description<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Data<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Dataframe<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">hue<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Variable in data to map plot aspects to different colors<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">palette<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Set of colors for mapping the hue variable<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">kind<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kind of plot for the non-identity relationships. {\u2018scatter\u2019, \u2018reg\u2019}<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">diag_kind<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Kind of plot for the diagonal subplots. {\u2018hist\u2019, \u2018kde\u2019}<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">Ex:<\/span> <b>import <\/b><span style=\"font-weight: 400;\">pandas <\/span><b>as <\/b><span style=\"font-weight: 400;\">pd<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;iris&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.set_style(<\/span><b>&#8220;ticks&#8221;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.pairplot(df,<\/span><span style=\"font-weight: 400;\">hue <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8216;species&#8217;<\/b><span style=\"font-weight: 400;\">,<\/span><span style=\"font-weight: 400;\">diag_kind <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;kde&#8221;<\/b><span style=\"font-weight: 400;\">,<\/span><span style=\"font-weight: 400;\">kind <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;scatter&#8221;<\/b><span style=\"font-weight: 400;\">,<\/span><span style=\"font-weight: 400;\">palette <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;husl&#8221;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><strong>Output()<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2767\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/paiwise-1024x503.png\" alt=\"Python Seaborn Tutorial \" width=\"850\" height=\"418\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/paiwise-1024x503.png 1024w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/paiwise-300x147.png 300w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/paiwise-768x377.png 768w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/paiwise-1200x589.png 1200w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/paiwise.png 1366w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3>Seaborn &#8211; Plotting Categorical Data<\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Scatter plots are not suitable when the variable under study is categorical.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">When one or both variables under study are categorical, we use plots like striplot(), swarmplot(), etc, Seaborn provides an interface to do so.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Categorical Scatter Plots:<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><b>stripplot()<\/b><\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">stripplot() is used when one of the variables under study is categorical. It presents the data in sorted order along any one of the axis.<\/span><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">pandas <\/span><b>as <\/b><span style=\"font-weight: 400;\">pd<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;iris&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.stripplot(<\/span><span style=\"font-weight: 400;\">x <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;species&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">y <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;petal_length&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">data <\/span><span style=\"font-weight: 400;\">= df)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2768\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/stripplot.png\" alt=\"Python Seaborn Tutorial \" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/stripplot.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/stripplot-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">In the above graph, we can clearly view the difference of petal_length in each species. But, the major issue with the above scatter plot is that points on the scatter plot are overlapped. We use the \u2018Jitter\u2019 parameter to handle this kind of scenario.<\/span><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;iris&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.stripplot(<\/span><span style=\"font-weight: 400;\">x <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;species&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">y <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;petal_length&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">data <\/span><span style=\"font-weight: 400;\">= df, <\/span><span style=\"font-weight: 400;\">jitter <\/span><span style=\"font-weight: 400;\">= <\/span><b>True<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2768\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/stripplot.png\" alt=\"Python Seaborn Tutorial \" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/stripplot.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/stripplot-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3><strong>Swarmplot()<\/strong><\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Another option which we can use as an alternative to \u2018Jitter\u2019 is a function swarmplot().\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This function places each point of scatter plot over categorical axis and hence avoids overlapping points.<\/span><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;iris&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.swarmplot(<\/span><span style=\"font-weight: 400;\">x <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;species&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">y <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;petal_length&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">data <\/span><span style=\"font-weight: 400;\">= df)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<h2><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2769\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/swarnplot.png\" alt=\"Python Seaborn Tutorial \" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/swarnplot.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/swarnplot-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/h2>\n<p>&nbsp;<\/p>\n<h2><b>Seaborn &#8211;<\/b> Distribution<b> of Observations<\/b><\/h2>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">In categorical scatter plots the approach becomes limited in the information, it can provide about the distribution of values within each category. Now, going further, let&#8217;s see what facilitates us with the comparison within categories.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><strong>Box Plots<\/strong><\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Boxplot is convenient to visualize the distribution of data through their quartiles.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Box plots normally have vertical lines extending from the boxes which are termed as whiskers. These whiskers denote variability outside the upper and lower quartiles, therefore Box Plots are also termed as box-and-whisker plot and box-and-whisker diagram. Any Outliers in data are plotted as individual points.<\/span><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;iris&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.boxplot(<\/span><span style=\"font-weight: 400;\">x <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;species&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">y <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;petal_length&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">data <\/span><span style=\"font-weight: 400;\">= df)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2771\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/boxplot.png\" alt=\"Python Seaborn Tutorial \" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/boxplot.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/boxplot-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3><strong>Violin Plots<\/strong><\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Violin Plots are a combination of both box plot with the kernel density estimates. So, these plots are easier to analyze and understand the distribution of the data.<\/span><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;tips&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.violinplot(<\/span><span style=\"font-weight: 400;\">x <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;day&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">y <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;total_bill&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">data<\/span><span style=\"font-weight: 400;\">=df)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2770\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/voilen-1.png\" alt=\"Python Seaborn Tutorial \" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/voilen-1.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/voilen-1-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">The quartile and whisker values from the boxplot are shown in the violin. As the violin plot uses KDE, the wider portion of the violin denotes higher density and the narrow region represents relatively lower density. The Inter-Quartile range in boxplot and higher density portion in kde lie in the same region of each category of the violin plot.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The above plot displays distribution of total_bill on four days of the week. But, in addition to that, if we want to see how distribution behaves with respect to sex, let&#8217;s explore it:<\/span><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;tips&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.violinplot(<\/span><span style=\"font-weight: 400;\">x <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;day&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">y <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;total_bill&#8221;<\/b><span style=\"font-weight: 400;\">,<\/span><span style=\"font-weight: 400;\">hue <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8216;sex&#8217;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">data <\/span><span style=\"font-weight: 400;\">= df)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2772\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/hue.png\" alt=\"Data Visualization in Python: Matplotlib vs Seaborn\" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/hue.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/hue-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Now from the above, we can clearly visualize spending behavior between males and females. We can easily tell that; a man makes more bills than a woman by looking at the graph.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><b>Seaborn &#8211;<\/b> Statistical<b> Estimation<\/b><\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">In most of the scenarios, we deal with predictions of the whole distribution of the data. But when it comes to central tendency predictions, we require a specific way to summarize the distribution. Mean and median are the very regularly used techniques to predict the central tendency of the distribution.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In all the plots that we learned until now, we made the visualization of the whole distribution. Now, let us discuss the plots with which we can predict the central tendency of the distribution.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><b>Bar Plot<\/b><\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">The barplot() displays the relationship between a categorical variable and a continuous variable. The dataset is represented in rectangular bars where length the bar represents the proportion of the dataset in that category.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The bar plot indicates the estimate of central tendency. Let us use the \u2018titanic\u2019 dataset to learn bar plots.<\/span><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;titanic&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.barplot(<\/span><span style=\"font-weight: 400;\">x <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;sex&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">y <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;survived&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">hue <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;class&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">data <\/span><span style=\"font-weight: 400;\">= df)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2773\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/barplot.png\" alt=\"Data Visualization in Python: Matplotlib vs Seaborn\" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/barplot.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/barplot-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">In this example, we can view the average quantity of survivals of males and females in each class. From the graph we can understand, more quantity of females survived than males. In both males and females, more quantity of survival is from the first class.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">A special case in barplot is to visualize the no of observations in each category instead of computing a statistic for a second variable. For this, we use <\/span><b>countplot().<\/b><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;titanic&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.countplot(<\/span><span style=\"font-weight: 400;\">x <\/span><span style=\"font-weight: 400;\">=<\/span><b>&#8221; class &#8220;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">data <\/span><span style=\"font-weight: 400;\">= df, <\/span><span style=\"font-weight: 400;\">palette <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;Blues&#8221;<\/b><span style=\"font-weight: 400;\">);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2775\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/bargraph.png\" alt=\"Data Visualization in Python: Matplotlib vs Seaborn\" width=\"850\" height=\"588\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/bargraph.png 500w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/bargraph-300x208.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Plot clarifies that, number of passengers in third class are higher than first and second class.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><b>Point Plots<\/b><\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Point plots are the same as bar plots but in a different style. Instead of the full bar, the value of the prediction is represented by the point at a certain height on the other axis.<\/span><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;titanic&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.pointplot(<\/span><span style=\"font-weight: 400;\">x <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;sex&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">y <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;survived&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">hue <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;class&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">data <\/span><span style=\"font-weight: 400;\">= df)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2776\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/pointplt.png\" alt=\"Data Visualization in Python: Matplotlib vs Seaborn\" width=\"850\" height=\"638\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/pointplt.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/pointplt-300x225.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2><b>Seaborn &#8211;<\/b> Plotting<b> Wide Form Data<\/b><\/h2>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">It is always preferred to use \u2018long-from\u2019 or \u2018tidy\u2019 datasets. But at times when we are left with no option other than to use a \u2018wide-form\u2019 dataset, same functions can also be implemented to \u201cwide-form\u201d data in a variety of formats, including Pandas Data Frames or two-dimensional NumPy arrays. These objects must be passed directly to the dataset parameter the x and y variables must be specified as strings<\/span><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;iris&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.boxplot(<\/span><span style=\"font-weight: 400;\">data <\/span><span style=\"font-weight: 400;\">= df, <\/span><span style=\"font-weight: 400;\">orient <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;h&#8221;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2778\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/wideplt-1024x503.png\" alt=\"Data Visualization in Python: Matplotlib vs Seaborn\" width=\"850\" height=\"418\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/wideplt-1024x503.png 1024w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/wideplt-300x147.png 300w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/wideplt-768x377.png 768w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/wideplt-1200x589.png 1200w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/wideplt.png 1366w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2><b>Seaborn<\/b> &#8211;<b> Multi Panel Categorical Plots<\/b><\/h2>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Categorical data can we displayed using two plots, you can either use the functions pointplot(), or the higher-level function factorplot().<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><b>Factorplot()<\/b><\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Factorplot plots a categorical plot on a FacetGrid. Using \u2018kind\u2019 parameter we can choose the plots like boxplot, violinplot, barplot and stripplot. FacetGrid uses pointplot by default.<\/span><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;exercise&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.factorplot(<\/span><span style=\"font-weight: 400;\">x <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;time&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">y <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;pulse&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">hue <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;kind&#8221;<\/b><span style=\"font-weight: 400;\">,<\/span><span style=\"font-weight: 400;\">data <\/span><span style=\"font-weight: 400;\">= df);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2795\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/kind.png\" alt=\"Data Visualization in Python: Matplotlib vs Seaborn\" width=\"850\" height=\"657\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/kind.png 603w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/kind-300x232.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">We can use different plot to display same data using the kind parameter<\/span><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;exercise&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.factorplot(<\/span><span style=\"font-weight: 400;\">x <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;time&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">y <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;pulse&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">hue <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;kind&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">kind <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8216;violin&#8217;<\/b><span style=\"font-weight: 400;\">,<\/span><span style=\"font-weight: 400;\">data <\/span><span style=\"font-weight: 400;\">= df);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2793\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/kinds.png\" alt=\"Data Visualization in Python: Matplotlib vs Seaborn\" width=\"850\" height=\"657\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/kinds.png 603w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/kinds-300x232.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3><b>What is<\/b> Facet<b> Grid?<\/b><\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Facet grid forms a matrix of panels defined by rows and columns by dividing the variables. Due to panels, a single plot looks like multiple plots. It is very helpful to analyze all combinations in 2 discrete variables.<\/span><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;exercise&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.factorplot(<\/span><span style=\"font-weight: 400;\">x <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;time&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">y <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;pulse&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">hue <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;kind&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">kind <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8216;violin&#8217;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">col <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;diet&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">data <\/span><span style=\"font-weight: 400;\">= df);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2794\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/fact-1024x433.png\" alt=\"Data Visualization in Python: Matplotlib vs Seaborn\" width=\"850\" height=\"359\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/fact-1024x433.png 1024w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/fact-300x127.png 300w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/fact-768x324.png 768w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/fact.png 1103w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">The facility of using Facet is, we can input another variable into the graph. The above graph is divided into two plots based on a third variable called \u2018diet\u2019 using the \u2018col\u2019 parameter.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We can make many column facets and align them with the rows of the grid:<\/span><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;titanic&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.factorplot(<\/span><b>&#8220;alive&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">col <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;deck&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">col_wrap <\/span><span style=\"font-weight: 400;\">= <\/span><span style=\"font-weight: 400;\">3<\/span><span style=\"font-weight: 400;\">,<\/span><span style=\"font-weight: 400;\">data <\/span><span style=\"font-weight: 400;\">= df[df.deck.notnull()],<\/span><span style=\"font-weight: 400;\">kind <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;count&#8221;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2792\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/deck-1-1024x503.png\" alt=\"Visualization with Seaborn \" width=\"850\" height=\"418\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/deck-1-1024x503.png 1024w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/deck-1-300x147.png 300w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/deck-1-768x377.png 768w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/deck-1-1200x589.png 1200w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/deck-1.png 1366w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Mostly, we use data that contain multiple quantitative variables, and the goal of an analysis is to relate those variables to each other. This can be done by regression lines.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">While building regression models, we normally check for multicollinearity, where we need to visualize the correlation between all the combinations of continuous variables and will take the required action to remove multicollinearity if exists. In such cases, the following techniques help.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><span style=\"font-weight: 400;\">Functions to Draw Linear Regression Models<\/span><\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">There are two main functions in Seaborn to visualize a linear relationship identified through regression.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">They are regplot() and lmplot().<\/span><\/p>\n<p>&nbsp;<\/p>\n<table>\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400;\">regplot<\/span><\/td>\n<td><span style=\"font-weight: 400;\">lmplot<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">accepts the x and y variables in a variety of formats includes simple numpy arrays, pandas Series objects, or as references to variables in a pandas DataFrame<\/span><\/td>\n<td><span style=\"font-weight: 400;\">has a dataset as a required parameter and the x and y variables must be specified as strings. This data format is called \u201clong-form\u201d data<\/span><\/td>\n<\/tr>\n<tr>\n<td><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;tips&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.regplot(<\/span><span style=\"font-weight: 400;\">x <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;total_bill&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">y <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;tip&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">data <\/span><span style=\"font-weight: 400;\">= df)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/td>\n<td><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;tips&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.lmplot(<\/span><span style=\"font-weight: 400;\">x <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;total_bill&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">y <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;tip&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">data <\/span><span style=\"font-weight: 400;\">= df)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/td>\n<\/tr>\n<tr>\n<td><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2789\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/regplot.png\" alt=\"\" width=\"640\" height=\"480\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/regplot.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/regplot-300x225.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/td>\n<td><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2791\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/regplot-1.png\" alt=\"\" width=\"640\" height=\"480\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/regplot-1.png 640w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/regplot-1-300x225.png 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">We can also fit a linear regression when one of the variables takes discrete values<\/span><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;tips&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.lmplot(<\/span><span style=\"font-weight: 400;\">x <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;size&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">y <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;tip&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">data <\/span><span style=\"font-weight: 400;\">= df)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2788\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/discretval.png\" alt=\"Visualization with Seaborn \" width=\"850\" height=\"850\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/discretval.png 500w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/discretval-150x150.png 150w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/discretval-300x300.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><\/h3>\n<h3><b>Fitting Different Kinds<\/b> of<b> Models<\/b><\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">In most of the cases, the dataset is non-linear and the above methods cannot generalize the regression line.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Let us use Anscombe\u2019s dataset with the regression plots:<\/span><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;anscombe&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.lmplot(<\/span><span style=\"font-weight: 400;\">x <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;x&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">y <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;y&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">data <\/span><span style=\"font-weight: 400;\">= df.query(<\/span><b>&#8220;dataset == &#8216;II'&#8221;<\/b><span style=\"font-weight: 400;\">))<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2787\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/ansq.png\" alt=\"Visualization with Seaborn \" width=\"850\" height=\"850\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/ansq.png 500w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/ansq-150x150.png 150w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/ansq-300x300.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">The plot displays the high deviation of data points from a regression line. These non-linear, higher order can be visualized using the lmplot() and regplot().These can fit a polynomial regression model to explore simple kinds of nonlinear trends in the datasets :<\/span><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;anscombe&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">sb.lmplot(<\/span><span style=\"font-weight: 400;\">x <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;x&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">y <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;y&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">data <\/span><span style=\"font-weight: 400;\">= df.query(<\/span><b>&#8220;dataset == &#8216;II'&#8221;<\/b><span style=\"font-weight: 400;\">),<\/span><span style=\"font-weight: 400;\">order <\/span><span style=\"font-weight: 400;\">= <\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2786\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/nolin.png\" alt=\"Visualization with Seaborn \" width=\"850\" height=\"850\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/nolin.png 500w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/nolin-150x150.png 150w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/nolin-300x300.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<h3><b>Seaborn &#8211;<\/b> Facet<b> Grid<\/b><\/h3>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">A useful approach to understand medium-dimensional data is by drawing multiple instances of the same plot over different subsets of your dataset.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This technique is normally known as \u201clattice\u201d, or \u201ctrellis\u201d plotting, and it is related to the idea of \u201csmall multiples\u201d.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To use these features, your data has to be in a Pandas DataFrame.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>Plotting Small Multiples of Data Subsets<\/b><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">We have already seen the FacetGrid example where FacetGrid class helps in displaying the distribution of one variable as well as the relationship between multiple variables separately within subsets of your dataset using multiple panels.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">A FacetGrid could be drawn with up to three dimensions \u2212 rows, cols, and hue. The first 2 have obvious correspondence with the resulting array of axes; think of the hue variable as the third dimension along a depth axis, where different levels are graphed with different colors.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">FacetGrid object takes a data frame as input and the names of variables that will form a row, column, or hue dimensions of the grid.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Variables must be categorical and data at each level of the variable will be used for a facet along that axis.<\/span><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;tips&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">g = sb.FacetGrid(df, <\/span><span style=\"font-weight: 400;\">col <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;time&#8221;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2785\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/fctgrid.png\" alt=\"Visualization with Seaborn \" width=\"850\" height=\"425\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/fctgrid.png 600w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/fctgrid-300x150.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Here we have just initialized the facet grid object which doesn\u2019t draw anything over them.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The main approach for displaying data over this grid is with the FacetGrid.map() method. Let\u2019s visualize the distribution of tips in each of these subsets, using a histogram.<\/span><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;tips&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">g = sb.FacetGrid(df, <\/span><span style=\"font-weight: 400;\">col <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;time&#8221;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">g.map(plt.hist, <\/span><b>&#8220;tip&#8221;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2784\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/facthist.png\" alt=\"Visualization with Seaborn \" width=\"850\" height=\"425\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/facthist.png 600w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/facthist-300x150.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">The no of plots is more than one because of the parameter col.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To make a relational plot, pass the multiple variable names.<\/span><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;tips&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">g = sb.FacetGrid(df, <\/span><span style=\"font-weight: 400;\">col <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;sex&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">hue <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;smoker&#8221;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">g.map(plt.scatter, <\/span><b>&#8220;total_bill&#8221;<\/b><span style=\"font-weight: 400;\">, <\/span><b>&#8220;tip&#8221;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2783\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/facts.png\" alt=\"Visualization with Seaborn \" width=\"850\" height=\"425\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/facts.png 600w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/facts-300x150.png 300w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2><b>Seaborn &#8211;<\/b> Pair<b> Grid<\/b><\/h2>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">PairGrid allows us to plot a grid of subplots using same plot type to visualize a dataset.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Unlike FacetGrid, it uses a different pair of variables for every subplot. It creates a matrix of sub-plots. It is also called a \u201cscatterplot matrix\u201d.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The usage of pairgrid is similar to facetgrid. First initialise the grid and then pass plotting function.<\/span><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;iris&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">g = sb.PairGrid(df)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">g.map(plt.scatter);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2782\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/pairgrid-1-1024x503.png\" alt=\"seaborn data visualization library in python\" width=\"850\" height=\"418\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/pairgrid-1-1024x503.png 1024w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/pairgrid-1-300x147.png 300w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/pairgrid-1-768x377.png 768w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/pairgrid-1-1200x589.png 1200w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/pairgrid-1.png 1366w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">It is also possible to plot different functions on the diagonal to show the univariate distribution of variable in each column.<\/span><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;iris&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">g = sb.PairGrid(df)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">g.map_diag(plt.hist)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">g.map_offdiag(plt.scatter);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2781\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/pairgrid1-1024x503.png\" alt=\"seaborn data visualization library in python\" width=\"850\" height=\"418\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/pairgrid1-1024x503.png 1024w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/pairgrid1-300x147.png 300w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/pairgrid1-768x377.png 768w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/pairgrid1-1200x589.png 1200w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/pairgrid1.png 1366w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">We can use different functions in the upper and lower triangles to view different aspects of relationship.<\/span><\/p>\n<p><b>import <\/b><span style=\"font-weight: 400;\">seaborn <\/span><b>as <\/b><span style=\"font-weight: 400;\">sb<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><b>from <\/b><span style=\"font-weight: 400;\">matplotlib <\/span><b>import <\/b><span style=\"font-weight: 400;\">pyplot <\/span><b>as <\/b><span style=\"font-weight: 400;\">plt<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">df = sb.load_dataset(<\/span><b>&#8216;iris&#8217;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">g = sb.PairGrid(df)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">g.map_upper(plt.scatter)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">g.map_lower(sb.kdeplot, <\/span><span style=\"font-weight: 400;\">cmap <\/span><span style=\"font-weight: 400;\">= <\/span><b>&#8220;Blues_d&#8221;<\/b><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">g.map_diag(sb.kdeplot, <\/span><span style=\"font-weight: 400;\">lw <\/span><span style=\"font-weight: 400;\">= <\/span><span style=\"font-weight: 400;\">3<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">legend <\/span><span style=\"font-weight: 400;\">= <\/span><b>False<\/b><span style=\"font-weight: 400;\">);<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">plt.show()<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2780\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/pairedgrid2-1024x503.png\" alt=\"seaborn data visualization library in python\" width=\"850\" height=\"418\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/pairedgrid2-1024x503.png 1024w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/pairedgrid2-300x147.png 300w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/pairedgrid2-768x377.png 768w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/pairedgrid2-1200x589.png 1200w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/pairedgrid2.png 1366w\" sizes=\"auto, (max-width: 850px) 100vw, 850px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>We hope you understand sets in Python Data Visualisation using Seaborn concepts.Get success in your career as a <a href=\"https:\/\/prwatech.in\/python-training-institute-in-bangalore\/\" title=\"online python course\">Python developer<\/a> by being a part of the <a href=\"https:\/\/prwatech.com\/\" title=\"online course to learn python\">Prwatech<\/a>, India&#8217;s leading <a href=\"https:\/\/prwatech.in\/python-training-institute-in-bangalore\/\" title=\"online python course with certificate\">Python training institute in Bangalore<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Seaborn Library for Data Visualization in Python &nbsp; Seaborn Library for Data Visualization in Python, welcome to the world of\u00a0 Python data visualization using seaborn. Are you the one who is looking forward to knowing the Seaborn Library for Data Visualization in Python? Or the one who is very keen to explore the Seaborn [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3331,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28],"tags":[542,545,547,70],"class_list":["post-2755","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-online-python-training-course","tag-python-training-course-online","tag-python-training-online","tag-seaborn-library-for-data-visualization-in-python"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Seaborn-Data Visualising library in python with MatPlotLib<\/title>\n<meta name=\"description\" content=\"Seaborn Library for Data Visualization in Python with MatPlotLib, In the world of Analytics, way to get insight details is by visualizing the dataset.\u00a0\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/prwatech.in\/blog\/python\/seaborn-data-visualising-library-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Seaborn-Data Visualising library in python with MatPlotLib\" \/>\n<meta property=\"og:description\" content=\"Seaborn Library for Data Visualization in Python with MatPlotLib, In the world of Analytics, way to get insight details is by visualizing the dataset.\u00a0\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prwatech.in\/blog\/python\/seaborn-data-visualising-library-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Prwatech\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prwatech.in\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-08-19T05:55:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-07-10T05:16:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Seaborn-Library-for-Data-Visualization-in-Python.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"960\" \/>\n\t<meta property=\"og:image:height\" content=\"550\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Prwatech\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:site\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prwatech\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"22 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prwatech.in\/blog\/python\/seaborn-data-visualising-library-in-python\/\",\"url\":\"https:\/\/prwatech.in\/blog\/python\/seaborn-data-visualising-library-in-python\/\",\"name\":\"Seaborn-Data Visualising library in python with MatPlotLib\",\"isPartOf\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prwatech.in\/blog\/python\/seaborn-data-visualising-library-in-python\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prwatech.in\/blog\/python\/seaborn-data-visualising-library-in-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Seaborn-Library-for-Data-Visualization-in-Python.jpg\",\"datePublished\":\"2019-08-19T05:55:05+00:00\",\"dateModified\":\"2020-07-10T05:16:24+00:00\",\"author\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\"},\"description\":\"Seaborn Library for Data Visualization in Python with MatPlotLib, In the world of Analytics, way to get insight details is by visualizing the dataset.\u00a0\",\"breadcrumb\":{\"@id\":\"https:\/\/prwatech.in\/blog\/python\/seaborn-data-visualising-library-in-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prwatech.in\/blog\/python\/seaborn-data-visualising-library-in-python\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/python\/seaborn-data-visualising-library-in-python\/#primaryimage\",\"url\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Seaborn-Library-for-Data-Visualization-in-Python.jpg\",\"contentUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Seaborn-Library-for-Data-Visualization-in-Python.jpg\",\"width\":960,\"height\":550,\"caption\":\"Seaborn Library for Data Visualization in Python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prwatech.in\/blog\/python\/seaborn-data-visualising-library-in-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/prwatech.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Seaborn Library for Data Visualization in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/prwatech.in\/blog\/#website\",\"url\":\"https:\/\/prwatech.in\/blog\/\",\"name\":\"Prwatech\",\"description\":\"Share Ideas, Start Something Good.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/prwatech.in\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\",\"name\":\"Prwatech\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"caption\":\"Prwatech\"},\"url\":\"https:\/\/prwatech.in\/blog\/author\/prwatech123\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Seaborn-Data Visualising library in python with MatPlotLib","description":"Seaborn Library for Data Visualization in Python with MatPlotLib, In the world of Analytics, way to get insight details is by visualizing the dataset.\u00a0","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/prwatech.in\/blog\/python\/seaborn-data-visualising-library-in-python\/","og_locale":"en_US","og_type":"article","og_title":"Seaborn-Data Visualising library in python with MatPlotLib","og_description":"Seaborn Library for Data Visualization in Python with MatPlotLib, In the world of Analytics, way to get insight details is by visualizing the dataset.\u00a0","og_url":"https:\/\/prwatech.in\/blog\/python\/seaborn-data-visualising-library-in-python\/","og_site_name":"Prwatech","article_publisher":"https:\/\/www.facebook.com\/prwatech.in\/","article_published_time":"2019-08-19T05:55:05+00:00","article_modified_time":"2020-07-10T05:16:24+00:00","og_image":[{"width":960,"height":550,"url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Seaborn-Library-for-Data-Visualization-in-Python.jpg","type":"image\/jpeg"}],"author":"Prwatech","twitter_card":"summary_large_image","twitter_creator":"@Eduprwatech","twitter_site":"@Eduprwatech","twitter_misc":{"Written by":"Prwatech","Est. reading time":"22 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/prwatech.in\/blog\/python\/seaborn-data-visualising-library-in-python\/","url":"https:\/\/prwatech.in\/blog\/python\/seaborn-data-visualising-library-in-python\/","name":"Seaborn-Data Visualising library in python with MatPlotLib","isPartOf":{"@id":"https:\/\/prwatech.in\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prwatech.in\/blog\/python\/seaborn-data-visualising-library-in-python\/#primaryimage"},"image":{"@id":"https:\/\/prwatech.in\/blog\/python\/seaborn-data-visualising-library-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Seaborn-Library-for-Data-Visualization-in-Python.jpg","datePublished":"2019-08-19T05:55:05+00:00","dateModified":"2020-07-10T05:16:24+00:00","author":{"@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3"},"description":"Seaborn Library for Data Visualization in Python with MatPlotLib, In the world of Analytics, way to get insight details is by visualizing the dataset.\u00a0","breadcrumb":{"@id":"https:\/\/prwatech.in\/blog\/python\/seaborn-data-visualising-library-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prwatech.in\/blog\/python\/seaborn-data-visualising-library-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/python\/seaborn-data-visualising-library-in-python\/#primaryimage","url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Seaborn-Library-for-Data-Visualization-in-Python.jpg","contentUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2019\/08\/Seaborn-Library-for-Data-Visualization-in-Python.jpg","width":960,"height":550,"caption":"Seaborn Library for Data Visualization in Python"},{"@type":"BreadcrumbList","@id":"https:\/\/prwatech.in\/blog\/python\/seaborn-data-visualising-library-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/prwatech.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Seaborn Library for Data Visualization in Python"}]},{"@type":"WebSite","@id":"https:\/\/prwatech.in\/blog\/#website","url":"https:\/\/prwatech.in\/blog\/","name":"Prwatech","description":"Share Ideas, Start Something Good.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/prwatech.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3","name":"Prwatech","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","caption":"Prwatech"},"url":"https:\/\/prwatech.in\/blog\/author\/prwatech123\/"}]}},"_links":{"self":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/2755","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/comments?post=2755"}],"version-history":[{"count":13,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/2755\/revisions"}],"predecessor-version":[{"id":5382,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/2755\/revisions\/5382"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media\/3331"}],"wp:attachment":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media?parent=2755"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/categories?post=2755"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/tags?post=2755"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}