{"id":4055,"date":"2020-03-16T19:12:41","date_gmt":"2020-03-16T19:12:41","guid":{"rendered":"https:\/\/www.askpython.com\/?p=4055"},"modified":"2023-02-16T19:57:12","modified_gmt":"2023-02-16T19:57:12","slug":"python-seaborn-tutorial","status":"publish","type":"post","link":"https:\/\/www.askpython.com\/python-modules\/python-seaborn-tutorial","title":{"rendered":"Python Seaborn Tutorial"},"content":{"rendered":"\n<p><strong>Python Seaborn module<\/strong> serves the purpose of Data Visualization at an ease with higher efficiency. In order to represent the variations in a huge data set, <code>data visualization<\/code> is considered as the best way to depict and analyze the data.<\/p>\n\n\n\n<p>Seaborn stands out to have a better set of functions to carry out data visualization than Matplotlib in an optimized and efficient manner. It supports NumPy and Pandas data structure to represent the data sets.<\/p>\n\n\n\n<p>But, in order to get started with the Seaborn module, I would strongly recommend the readers to understand the <a href=\"https:\/\/www.askpython.com\/python-modules\/matplotlib\/python-matplotlib\" class=\"rank-math-link\">Python Matplotlib module<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Getting started with Python Seaborn<\/h2>\n\n\n\n<p>In order to get started with the functionalities of Seaborn module, we need to install the module in our environment using the below command:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\npip install Seaborn\n<\/pre><\/div>\n\n\n<p>Seaborn module requires the following modules installed to work in a smooth manner:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Matplotlib<\/li><li><a class=\"rank-math-link rank-math-link\" href=\"https:\/\/www.askpython.com\/python-modules\/numpy\/python-numpy-arrays\">NumPy<\/a><\/li><li><a class=\"rank-math-link rank-math-link\" href=\"https:\/\/www.askpython.com\/python-modules\/pandas\/python-pandas-module-tutorial\">Pandas<\/a><\/li><li><a class=\"rank-math-link rank-math-link\" href=\"https:\/\/www.askpython.com\/python-modules\/python-scipy\">SciPy<\/a><\/li><\/ul>\n\n\n\n<p>I&#8217;ve linked the bullet points with the relevant articles for reference.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Data Files Used Throughout the Tutorial<\/h2>\n\n\n\n<p>We&#8217;ll be working with CSV files throughout the tutorial, so this section highlights the files that we&#8217;ll be using throughout. <\/p>\n\n\n\n<p>Wherever you see a reference to the following file names, you can look back at this section to understand the data that&#8217;s being passed.<\/p>\n\n\n\n<p><strong>Book1.csv:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"324\" height=\"287\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Input_csv1.png\" alt=\"Input csv file\" class=\"wp-image-4091\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Input_csv1.png 324w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Input_csv1-300x266.png 300w\" sizes=\"auto, (max-width: 324px) 100vw, 324px\" \/><figcaption><strong>Book1.csv<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<p><strong>tips.csv<\/strong>:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1158\" height=\"785\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Input_csv_tips.png\" alt=\"Input Csv Tips\" class=\"wp-image-4129\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Input_csv_tips.png 1158w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Input_csv_tips-300x203.png 300w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Input_csv_tips-1024x694.png 1024w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Input_csv_tips-768x521.png 768w\" sizes=\"auto, (max-width: 1158px) 100vw, 1158px\" \/><figcaption><strong>Input csv tips-data set<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Python Seaborn For Statistical Analysis<\/h2>\n\n\n\n<p><strong>Statistical Analysis<\/strong> is the basic <code>estimation<\/code> out of some parameters of the data-set to a large extent. Data Visualization can be considered as the best way to perform statistical analysis i.e. predict the outcome or the cause based on diagrammatic values.<\/p>\n\n\n\n<p>Either of the following ways can be taken into consideration during the statistical analysis:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>seaborn.scatterplot()<\/strong><\/li><li><strong>seaborn.lineplot()<\/strong><\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">1. seaborn.scatterplot()<\/h3>\n\n\n\n<p>The <code>seaborn.scatterplot()<\/code> function is basically used to depict the relationship between the parameters on the given axes respectively. Every point on the graph depicts a value corresponding to it.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nseaborn.scatterplot(x=value, y=value, data=data)\n<\/pre><\/div>\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport seaborn\nimport pandas\nimport matplotlib.pyplot as plt\n\ncsv = pandas.read_csv(r&#039;C:\\Book1.csv&#039;)\nres = seaborn.scatterplot(x=&quot;Name&quot;, y=&quot;Age&quot;, data=csv)\nplt.show()\n<\/pre><\/div>\n\n\n<p>In the above example, we have imported <strong>Python Pandas module<\/strong> in order to use the <code>read_csv()<\/code> function to read the contents of the data set.<\/p>\n\n\n\n<p>The column-&#8216;Name&#8217; is represented by the x-axis and the column-&#8216;Age&#8217; by the y-axis.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"528\" height=\"330\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-ScatterPlot.png\" alt=\"Python Seaborn-ScatterPlot\" class=\"wp-image-4059\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-ScatterPlot.png 528w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-ScatterPlot-300x188.png 300w\" sizes=\"auto, (max-width: 528px) 100vw, 528px\" \/><figcaption><strong>Seaborn ScatterPlot<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2. seaborn.lineplot()<\/h3>\n\n\n\n<p>The <code>seaborn.lineplot()<\/code> function can be extensively used in situations wherein we feel the need to check the dependency of a parameter on the other in a continuous manner relative to time.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nseabron.lineplot(x=value, y=value, data=data)\n<\/pre><\/div>\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport seaborn\nimport pandas\nimport matplotlib.pyplot as plt\ncsv = pandas.read_csv(r&#039;C:\\Book1.csv&#039;)\nres = seaborn.lineplot(x=&quot;Name&quot;, y=&quot;Age&quot;, data=csv)\nplt.show()\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"520\" height=\"332\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-LinePlot.png\" alt=\"Seaborn-LinePlot\" class=\"wp-image-4060\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-LinePlot.png 520w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-LinePlot-300x192.png 300w\" sizes=\"auto, (max-width: 520px) 100vw, 520px\" \/><figcaption><strong>Seaborn LinePlot<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Categorical Scatter Plot<\/h2>\n\n\n\n<p>Categorical data divides and represents itself in the form of discrete groups i.e. a subset of the original data.<\/p>\n\n\n\n<p>Python Seaborn module contains the following methods to represent and visualize categorical data:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>seaborn.catplot()<\/strong><\/li><li><strong>seaborn.stripplot()<\/strong><\/li><li><strong>seaborn.swarmplot()<\/strong><\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">1. seaborn.catplot()<\/h3>\n\n\n\n<p>The <code>seaborn.catplot()<\/code> function, as mentioned above, is one of the techniques to analyze the relationship between a numeric value and a categorical group of values together.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nseaborn.catplot(x=value, y=value, data=data)\n<\/pre><\/div>\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport seaborn\nimport pandas\nimport matplotlib.pyplot as plt\n\n\ncsv = seaborn.load_dataset(&quot;tips&quot;)\nres = seaborn.catplot(x=&quot;tip&quot;, y=&quot;sex&quot;, data=csv)\n\nplt.show()\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"491\" height=\"441\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/catplot.png\" alt=\"Seaborn-catplot\" class=\"wp-image-4130\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/catplot.png 491w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/catplot-300x269.png 300w\" sizes=\"auto, (max-width: 491px) 100vw, 491px\" \/><figcaption><strong>catplot<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2. seaborn.stripplot()<\/h3>\n\n\n\n<p>The <code>seaborn.stripplot()<\/code> function considers one of the input columns as categorical data input and then it plots the points accordingly in an ordinal fashion despite the different data type of the input.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nseaborn.stripplot(x=value, y=value, data=data)\n<\/pre><\/div>\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport seaborn\nimport pandas\nimport matplotlib.pyplot as plt\n\n\ncsv = seaborn.load_dataset(&quot;tips&quot;)\nres = seaborn.stripplot(x=&quot;tip&quot;, y=&quot;sex&quot;, data=csv,jitter=0.05)\n\nplt.show()\n<\/pre><\/div>\n\n\n<p>The parameter <code>jitter<\/code> is useful when the data set consists of data points that overlap. In such cases, setting a jitter value can help them get <strong>uniformly distributed<\/strong>.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"564\" height=\"332\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/stripplot.png\" alt=\"Seaborn-stripplot\" class=\"wp-image-4131\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/stripplot.png 564w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/stripplot-300x177.png 300w\" sizes=\"auto, (max-width: 564px) 100vw, 564px\" \/><figcaption><strong>stripplot<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">3. seaborn.swarmplot()<\/h3>\n\n\n\n<p>The seaborn.swarmplot() function resembles the <strong>seaborn.stripplot()<\/strong> function with a slight difference. The <code>seaborn.swarmplot()<\/code> function plots the data values along the categorical axis chosen. Thus, it completely avoids <strong>overlapping<\/strong>.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nseaborn.swarmplot(x=value, y=value, data=data)\n<\/pre><\/div>\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport seaborn\nimport pandas\nimport matplotlib.pyplot as plt\n\n\ncsv = seaborn.load_dataset(&quot;tips&quot;)\nres = seaborn.swarmplot(x=&quot;tip&quot;, y=&quot;sex&quot;, data=csv)\n\nplt.show()\n<\/pre><\/div>\n\n\n<p>In the above example, I have passed the column &#8216;sex&#8217; as the only categorical data and have plotted against the same along the x-axis, respectively.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"575\" height=\"332\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/swarmplot.png\" alt=\"Seaborn-swarmplot\" class=\"wp-image-4132\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/swarmplot.png 575w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/swarmplot-300x173.png 300w\" sizes=\"auto, (max-width: 575px) 100vw, 575px\" \/><figcaption><strong>swarmplot<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Categorical Distribution Plots<\/h2>\n\n\n\n<p><strong>Categorical Distribution data<\/strong> basically refers to the type of data wherein the result describes the certain possibility of the random\/chosen variable to belong to one of the given <strong>possible categories<\/strong>.<\/p>\n\n\n\n<p>Python Seaborn has the following functions to represent the categorical distributed data efficiently:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>seaborn.violinplot()<\/strong><\/li><li><strong>seaborn.boxplot()<\/strong><\/li><li><strong>seaborn.boxenplot()<\/strong><\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">1. seaborn.violinplot()<\/h3>\n\n\n\n<p>The <code>seaborn.violinplot()<\/code> function represents the underlying distribution of the data. It depicts and represents the distribution of data against different categorical data input.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nseaborn.violinplot(x=value, y=value, data=data)\n<\/pre><\/div>\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport seaborn\nimport pandas\nimport matplotlib.pyplot as plt\ncsv = pandas.read_csv(&quot;C:\\\\Book1.csv&quot;)\nres = seaborn.violinplot(x=csv&#x5B;&#039;Age&#039;])\nplt.show()\n<\/pre><\/div>\n\n\n<p>In the above example, we have considered the distribution of data along the column-&#8216;Age&#8217;, respectively.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"465\" height=\"326\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-violinplot.png\" alt=\"Seaborn-violinplot\" class=\"wp-image-4068\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-violinplot.png 465w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-violinplot-300x210.png 300w\" sizes=\"auto, (max-width: 465px) 100vw, 465px\" \/><figcaption><strong>Seaborn-violinplot<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2. seaborn.boxplot()<\/h3>\n\n\n\n<p>The <code>seaborn.boxplot()<\/code> function represents the <strong>categorical distribution<\/strong> of data and sets comparison among the different categorical data inputs. <\/p>\n\n\n\n<p>The <strong>&#8216;box&#8217; structure<\/strong> represents the <strong>main quartile of the data input<\/strong> while the <strong>&#8216;line&#8217; structure<\/strong> represents the rest of the <strong>distribution <\/strong>of data. The <strong>outliers <\/strong>are represented by points using an <strong>inter-quartile function<\/strong>.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nseaborn.boxplot(x=value, y=value, data=data)\n<\/pre><\/div>\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport seaborn\nimport pandas\nimport matplotlib.pyplot as plt\ncsv = pandas.read_csv(&quot;C:\\\\Book1.csv&quot;)\nres = seaborn.boxplot(x=csv&#x5B;&#039;Age&#039;])\nplt.show()\n<\/pre><\/div>\n\n\n<p>In the above example, we have used Book1.csv file as the input data set. <\/p>\n\n\n\n<p>If you try to analyze the data-set, you will find the Age-12 to be an outlier type of data and the rest of the data ranging between 15-27. This is represented well by the <strong>seaborn.boxplot()<\/strong> function.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"463\" height=\"329\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-boxplot.png\" alt=\"Seaborn-boxplot\" class=\"wp-image-4070\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-boxplot.png 463w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-boxplot-300x213.png 300w\" sizes=\"auto, (max-width: 463px) 100vw, 463px\" \/><figcaption><strong>Seaborn boxplot<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">3. seaborn.boxenplot()<\/h3>\n\n\n\n<p>The <code>seaborn.boxenplot()<\/code> function is quite similar to <strong>seaborn.boxplot()<\/strong> function with a slight difference in the representation. <\/p>\n\n\n\n<p>The <strong>seaborn.boxenplot()<\/strong> function represents the distribution of the categorical data in a way where the <strong>large quartiles <\/strong>represent the features corresponding to the actual data observations. It presents the data in a format that gives us a <strong>detailed information in a visualized form<\/strong> about the entire distribution of data.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nseaborn.boxenplot(x=value, y=value, data=data)\n<\/pre><\/div>\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport seaborn\nimport pandas\nimport matplotlib.pyplot as plt\ncsv = pandas.read_csv(&quot;C:\\\\Book1.csv&quot;)\nres = seaborn.boxenplot(x=csv&#x5B;&#039;Age&#039;])\nplt.show()\n<\/pre><\/div>\n\n\n<p>If you analyze and compare the below output with the input data set, it is clearly understood that <strong>boxenplot<\/strong> represents the entire distribution of the data points ranging between 12-27, along with the distribution of the categorical data with a large quartile-box structure. <\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"460\" height=\"326\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-boxenplot.png\" alt=\"Seaborn-boxenplot\" class=\"wp-image-4072\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-boxenplot.png 460w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-boxenplot-300x213.png 300w\" sizes=\"auto, (max-width: 460px) 100vw, 460px\" \/><figcaption><strong>Seaborn boxenplot<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Categorical estimate plots<\/h2>\n\n\n\n<p>The estimation of categorical data basically refers to the representation of certain estimation or prediction of the categorical data values to the corresponding data variable.<\/p>\n\n\n\n<p>Python Seaborn has the following functions to be used for the estimation of categorical data:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>seaborn.countplot()<\/strong><\/li><li><strong>seaborn.barplot()<\/strong><\/li><li><strong>seaborn.pointplot()<\/strong><\/li><\/ul>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">1. seaborn.countplot()<\/h3>\n\n\n\n<p>The <code>seaborn.counplot()<\/code> function is used to estimate and represent the categorical variable in terms of the frequency or count of it.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nseaborn.countplot(x=value, y=value, data=data)\n<\/pre><\/div>\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport seaborn\nimport pandas\nimport matplotlib.pyplot as plt\ncsv = pandas.read_csv(&quot;C:\\\\Book1.csv&quot;)\nres = seaborn.countplot(x=csv&#x5B;&#039;Age&#039;])\nplt.show()\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"525\" height=\"332\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-countplot.png\" alt=\"Seaborn-countplot\" class=\"wp-image-4074\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-countplot.png 525w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-countplot-300x190.png 300w\" sizes=\"auto, (max-width: 525px) 100vw, 525px\" \/><figcaption><strong>Seaborn countplot<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<p>As seen clearly in the above image, the <strong>countplot() function<\/strong> has basically counted the frequency of the input data field and represented it along the y-axis while the data field &#8211; &#8216;Age&#8217; being represented along the x-axis.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">2. seaborn.barplot()<\/h3>\n\n\n\n<p>The <code>seaborn.barplot()<\/code> function basically represents the estimated data in the form of the central tendency of the data representation.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport seaborn\nimport pandas\nimport matplotlib.pyplot as plt\ncsv = pandas.read_csv(&quot;C:\\\\Book1.csv&quot;)\nres = seaborn.barplot(x=csv&#x5B;&#039;Name&#039;], y=csv&#x5B;&#039;Age&#039;])\nplt.show()\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"525\" height=\"327\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-barplot.png\" alt=\"Seaborn-barplot\" class=\"wp-image-4075\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-barplot.png 525w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-barplot-300x187.png 300w\" sizes=\"auto, (max-width: 525px) 100vw, 525px\" \/><figcaption><strong>Seaborn barplot<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">3. seaborn.pointplot()<\/h3>\n\n\n\n<p>The <code>seaborn.pointplot()<\/code> function represents the estimation of the central tendency of the distribution with the help of scatter points and lines joining them.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nseaborn.pointplot(x=value, y=value, data=data)\n<\/pre><\/div>\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport seaborn\nimport pandas\nimport matplotlib.pyplot as plt\ncsv = pandas.read_csv(&quot;C:\\\\Book1.csv&quot;)\nres = seaborn.pointplot(x=csv&#x5B;&#039;Name&#039;], y=csv&#x5B;&#039;Age&#039;])\nplt.show()\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"503\" height=\"330\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-pointplot.png\" alt=\"Seaborn-pointplot\" class=\"wp-image-4077\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-pointplot.png 503w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-pointplot-300x197.png 300w\" sizes=\"auto, (max-width: 503px) 100vw, 503px\" \/><figcaption><strong>Seaborn pointplot<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Customized Styles and Themes in Seaborn<\/h2>\n\n\n\n<p>Python Seaborn has in-built functions and themes to visualize the data in a better and attractive manner.<\/p>\n\n\n\n<p>The <code>seaborn.set()<\/code> function is used for the <strong>default <\/strong>theme acquisition of the output visualization.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nseaborn.set()\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport seaborn\nimport pandas\nimport matplotlib.pyplot as plt\nseaborn.set()\ncsv = pandas.read_csv(&quot;C:\\\\Book1.csv&quot;)\nres = seaborn.pointplot(x=csv&#x5B;&#039;Name&#039;], y=csv&#x5B;&#039;Age&#039;])\nplt.show()\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"508\" height=\"331\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-style-using-set.png\" alt=\"Seaborn Style Using set()\" class=\"wp-image-4079\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-style-using-set.png 508w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-style-using-set-300x195.png 300w\" sizes=\"auto, (max-width: 508px) 100vw, 508px\" \/><figcaption><strong>Seaborn Style Using set()<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<p>Python Seaborn provides us with the following themes to work with and represent, visualize the data:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Ticks<\/strong><\/li><li><strong>Whitegrid theme<\/strong><\/li><li><strong>Darkgrid theme<\/strong><\/li><li><strong>Dark<\/strong><\/li><li><strong>White<\/strong><\/li><\/ul>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nseaborn.set_style(&quot;theme-name&quot;)\n<\/pre><\/div>\n\n\n<p><strong>Example: 1-<\/strong> <code>The dark theme<\/code><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport seaborn\nimport pandas\nimport matplotlib.pyplot as plt\nseaborn.set_style(&quot;dark&quot;)\ncsv = pandas.read_csv(&quot;C:\\\\Book1.csv&quot;)\nres = seaborn.pointplot(x=csv&#x5B;&#039;Name&#039;], y=csv&#x5B;&#039;Age&#039;])\nplt.show()\n<\/pre><\/div>\n\n\n<p><strong>Output: <\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"532\" height=\"340\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-dark-theme.png\" alt=\"Seaborn Dark Theme\" class=\"wp-image-4080\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-dark-theme.png 532w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-dark-theme-300x192.png 300w\" sizes=\"auto, (max-width: 532px) 100vw, 532px\" \/><figcaption><strong>Seaborn Dark Theme<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<p><strong>Example: 2- <\/strong><code>The whitegrid theme<\/code><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport seaborn\nimport pandas\nimport matplotlib.pyplot as plt\nseaborn.set_style(&quot;whitegrid&quot;)\ncsv = pandas.read_csv(&quot;C:\\\\Book1.csv&quot;)\nres = seaborn.pointplot(x=csv&#x5B;&#039;Name&#039;], y=csv&#x5B;&#039;Age&#039;])\nplt.show()\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"533\" height=\"341\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-whitegrid-theme.png\" alt=\"Seaborn Whitegrid Theme\" class=\"wp-image-4081\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-whitegrid-theme.png 533w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-whitegrid-theme-300x192.png 300w\" sizes=\"auto, (max-width: 533px) 100vw, 533px\" \/><figcaption><strong>Seaborn White grid Theme<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Multi-Plot grids in Seaborn<\/h2>\n\n\n\n<p>In order to represent the large data set with categorical values in a precise manner, we can draw <strong>multiple plots of the sub-sets of data<\/strong> to visualize it. <\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nseaborn.FacetGird(data, col=value, col_wrap=value)\n<\/pre><\/div>\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport seaborn\nimport pandas\nimport matplotlib.pyplot as plt\nseaborn.set_style(&quot;whitegrid&quot;)\ncsv = pandas.read_csv(&quot;C:\\\\Book1.csv&quot;)\nres = seaborn.FacetGrid(csv, col=&quot;Age&quot;, col_wrap=3)\nres.map(seaborn.barplot, &quot;Name&quot;, &quot;Age&quot;)\nplt.show()\n<\/pre><\/div>\n\n\n<p>The <code>FacetGrid class<\/code> is used to extensively represent the data with multiple plots against the sub-sets of data. It can be represented along the following dimensions:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>row<\/strong><\/li><li><strong>col<\/strong><\/li><li><strong>hue<\/strong><\/li><\/ul>\n\n\n\n<p>The parameter <code>col_wrap<\/code> basically represents the number of rows along which the graphs need to be represented.<\/p>\n\n\n\n<p>The <code>FacetGrid.map()<\/code> function is used to apply a plotting technique to every subset of the data.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"803\" height=\"790\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-multigrid.png\" alt=\"Seaborn Multigrid\" class=\"wp-image-4083\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-multigrid.png 803w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-multigrid-300x295.png 300w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-multigrid-768x756.png 768w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-multigrid-24x24.png 24w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-multigrid-48x48.png 48w\" sizes=\"auto, (max-width: 803px) 100vw, 803px\" \/><figcaption><strong>Seaborn Multigrid<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Plotting univariate distributions with Seaborn<\/h2>\n\n\n\n<p><strong>Univariate distribution<\/strong> basically refers to the <strong>distribution <\/strong>of the data with respect to a <strong>single random variable\/data item<\/strong>.<\/p>\n\n\n\n<p>Python Seaborn module&#8217;s <code>seaborn.distplot()<\/code> function can be used to represent the univariate distribution of data set.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nseaborn.distplot(data-column)\n<\/pre><\/div>\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport seaborn\nimport pandas\nimport matplotlib.pyplot as plt\nseaborn.set_style(&quot;whitegrid&quot;)\ncsv = pandas.read_csv(&quot;C:\\\\Book1.csv&quot;)\nres=seaborn.distplot(csv&#x5B;&#039;Age&#039;])\nplt.show()\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"506\" height=\"332\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-distplot.png\" alt=\"Seaborn Distplot\" class=\"wp-image-4087\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-distplot.png 506w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-distplot-300x197.png 300w\" sizes=\"auto, (max-width: 506px) 100vw, 506px\" \/><figcaption>Seaborn Distplot<\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Depicting bivariate distributions with Seaborn<\/h2>\n\n\n\n<p> <strong>Bivariate distribution<\/strong> refers to the visualization of data with respect to <strong>two data columns or items of the data set<\/strong>.<\/p>\n\n\n\n<p>The <code>seaborn.jointplot()<\/code> can be used to depict the relationship between the two data variables.<\/p>\n\n\n\n<p><strong>Syntax:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nseaborn.jointplot(x=variable1, y=variable2)\n<\/pre><\/div>\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport seaborn\nimport pandas\nimport matplotlib.pyplot as plt\nseaborn.set_style(&quot;darkgrid&quot;)\ncsv = pandas.read_csv(&quot;C:\\\\Book1.csv&quot;)\nres=seaborn.jointplot(x=csv&#x5B;&#039;Age&#039;], y=csv&#x5B;&#039;Age&#039;])\nplt.show()\n<\/pre><\/div>\n\n\n<p>In the above example, We have used both the variables as &#8216;Age&#8217; just for the sake of simplicity to depict the visualization of data.<\/p>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"546\" height=\"534\" src=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-jointplot.png\" alt=\"Seaborn jointplot\" class=\"wp-image-4088\" srcset=\"https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-jointplot.png 546w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-jointplot-300x293.png 300w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-jointplot-24x24.png 24w, https:\/\/www.askpython.com\/wp-content\/uploads\/2020\/03\/Seaborn-jointplot-48x48.png 48w\" sizes=\"auto, (max-width: 546px) 100vw, 546px\" \/><figcaption><strong>Seaborn jointplot<\/strong><\/figcaption><\/figure><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Thus, in this article, we have understood the basic functionality offered by <strong>Python Seaborn for data visualization<\/strong>.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">References<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/seaborn.pydata.org\/tutorial.html\" class=\"rank-math-link\" target=\"_blank\" rel=\"noopener\">Python Seaborn-Official Documentation<\/a><\/li><li>Python Seaborn tutorial-JournalDev<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Python Seaborn module serves the purpose of Data Visualization at an ease with higher efficiency. In order to represent the variations in a huge data set, data visualization is considered as the best way to depict and analyze the data. Seaborn stands out to have a better set of functions to carry out data visualization [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":4121,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-4055","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-modules"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts\/4055","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/comments?post=4055"}],"version-history":[{"count":0,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/posts\/4055\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/media\/4121"}],"wp:attachment":[{"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/media?parent=4055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/categories?post=4055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.askpython.com\/wp-json\/wp\/v2\/tags?post=4055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}