Seaborn
1. Seaborn
Seaborn is a very popular plotting library.2. Seaborn
It works well with tidy datasets, and can easily create bar plots, histograms, boxplots, and scatter plots. You can also quickly add additional aesthetics to enhance your plots and create facets.3. Seaborn histograms
We first import seaborn using the alias sns. Since seaborn is also built on matplotlib, we import matplotlib dot pyplot as plt. To plot a histogram, pass the relevant variable to the function as shown here, and call plt dot show() to display the plot.4. Seaborn count plot
You can use the countplot() function to draw a barplot. Here we draw a barplot by calling countplot() on 'species' and the data argument as iris. Note that we do not need to pre-tabulate the values before creating a barplot in seaborn.5. Seaborn boxplots
You can create boxplots with the boxplot() function as shown here. x and y arguments specify the columns to be plotted on the x and y axes respectively, and the data argument specifies the DataFrame.6. Seaborn scatterplots
You can create scatter plots with the regplot() function. Note that seaborn draws a regression line by default when plotting a scatter plot.7. Seaborn scatterplots w/out regression line
You can turn this feature off by setting the fit_reg argument to False.8. Seaborn facets
You can specify the row and col arguments in some seaborn functions which can be used to create facets. If you specify either row or col argument, then the function will create a facet along one axis. But if you specify both the row and col arguments, facets are created along both the axes.9. Seaborn FacetGrid
When you end up using a plotting function that does not automatically support facetting, you can manually create a facet grid object. To do this, we first use the FacetGrid() function with the data argument, that is, iris and specify col = 'species' to create facets of species along the x-axis and assign the result to g. We then call map() on g and specify a plotting function that will create the specific kind of plot we wish to create. Here we draw a histogram of the sepal_length column using the matplotlib histogram function plt dot hist. You will learn more about matplotlib functions in the next video.10. Let's practice!
Now it's your turn to create faceted plots using seaborn.Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.