Explain how a violin plot can be visualized using factorplot function in Python?

PythonServer Side ProgrammingProgramming

<p>The barplot function establishes the relationship between a categorical variable and a continuous variable. Data is represented in the form of rectangular bars where the length of the bar indicates the proportion of data in that specific category.</p><p>Point plots are similar to bar plots but instead of representing the fill bar, the estimated value of the data point is represented by a point at a specific height on the other axis.</p><p>Categorical data can be visualized using categorical scatter plots or two separate plots with the help of pointplot or a higher level function known as factorplot.</p><p>The factorplot function draws a categorical plot on a FacetGrid, with the help of parameter &lsquo;kind&rsquo;.</p><p>The value to &lsquo;kind&rsquo; parameter here would be &lsquo;violin&rsquo;. FacetGrid uses &lsquo;pointplot&rsquo; function by default.</p><p>Let us understand how a factorplot can be used to create a violin graph &minus;</p><h2>Example</h2><pre class="prettyprint notranslate">import pandas as pd import seaborn as sb from matplotlib import pyplot as plt my_df = sb.load_dataset(&#39;exercise&#39;) sb.factorplot(x = &quot;time&quot;, y = &quot;pulse&quot;, hue = &quot;kind&quot;, kind = &#39;violin&#39;,data = my_df); plt.show()</pre><h2>Output</h2><p><img src="https://www.tutorialspoint.com/assets/questions/media/46578/factorplot_function.jpg" class="fr-fic fr-dib" width="477" height="377"></p><h2>Explanation</h2><ul class="list"><li>The required packages are imported.</li><li>The input data is &lsquo;exercise&rsquo; which is loaded from the seaborn library.</li><li>This data is stored in a dataframe.</li><li>The &lsquo;load_dataset&rsquo; function is used to load the iris data.</li><li>This data is visualized using the &lsquo;factorplot&rsquo; function.</li><li>Here, the dataframe is supplied as parameter.</li><li>The &lsquo;kind&rsquo; parameter is specified as &lsquo;violin&rsquo; here.</li><li>Also, the x and y values are specified.</li><li>This data is displayed on the console.</li></ul>
Updated on 11-Dec-2020 10:56:01