Countplot in PythonIn this article, we will discuss how we can create a countplot using the seaborn library and how the different parameters can be used to infer results from the features of our dataset. Seaborn libraryThe seaborn library is widely used among data analysts, the galaxy of plots it contains provides the best possible representation of our data. The seaborn library can be imported into our working environment using- Let us now discuss why do we use countplot and what is the significance of its parameters. CountplotThe countplot is used to represent the occurrence(counts) of the observation present in the categorical variable. It uses the concept of a bar chart for the visual depiction. Parameters-The following parameters are specified when we create a countplot, let us get a brief idea of them-
Now let us see what are the different ways of representing our attributes. In the first example, we will create a countplot for a single variable. We have taken the dataset ‘tips’ to implement the same. 1. Value counts for a single variableExample – Output: In the next example, we will use the hue parameter and create a countplot. The following program illustrates the same- 2. Representing two categorical variables using hue parameterExample – Output: In the next example, we will consider the y axis and create a horizontal countplot. The following program illustrates the same- 3. Creating Horizontal PlotsExample – Output: Let us now have a look at how color palettes can enhance the presentation of our data. In the next example, we will use the parameter “palette”. The following program illustrates the same- 4. Using color palettesInput- Output: In the next example, we will use the parameter color and let us see how does it works? The following program illustrates the same- 5. Using a parameter ‘color’Example – Output: Now we will use the parameter ‘saturation’ and see how does it impact the representation of our data. The following program illustrates the same- 6. Using the parameter ‘saturation’Example – Output: And finally in the last example we will use the parameters linewidth and edgecolor.
Example – Output: |
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/263469.html