Seaborn provides several functions for creating multiple plots at the same time.
Let's start with jointplot(). It allows us to display a plot using x and y data, while also displaying an additional plot on each axis representing the distribution of the variable on that axis. Here is an example using the penguins dataset:
Importation Code
← Running
Cell 2
← Running
The for loop in the code allows us to display the individual points in addition to the plots. This is Matplotlib code.
An alternative that provides more control and customization is JointGrid(). In particular, it allows us to use different plot types for the central plot and for the plots on the axes.
Cell 3
← Running
plot_joint() controls the type of the central plot, while plot_marginals() controls the plots on the axes.
Another type of visualization is pairplot(). It allows us to display the plots for every possible pair of variables in a single figure, along with the distribution of each variable on the diagonal.
If our data contains the variables x, y, and z, we will have the following plots:
x versus y, y versus x
y versus z, z versus y
z versus x, x versus z
On the diagonal, we will have the distribution of x, y, and z.
Cell 4
← Running
We can change the type of plot on the diagonal and elsewhere using diag_kind for the diagonal and kind for the other plots. diag_kind can only take "hist" or "kde" as values, while kind also provides access to "scatter", which is the default value.
As with jointplot(), pairplot() has a complementary function that provides greater control and customization: PairGrid(). With this function, for example, we can choose different types of plots above and below the diagonal.
Cell 5
← Running
map_upper(), map_lower() and map_diag() allow you to control the different types of plots in the figure. They can be used with any type of Seaborn plotting function that accepts x and y arguments.
Finally, we have the FacetGrid() representation. Unlike the previous functions, it does not automatically create different types of plots within a figure. Instead, it allows us to manually organize the plots using col and row, while also providing the ability to customize individual plots within the figure. It is therefore a function that is somewhat closer to Matplotlib.