Get startedGet started for free

Using JointGrid and jointplot

1. Using JointGrid and jointplot

The final data-aware grid we will discuss is the JointGrid and its companion function, jointplot(). A JointGrid() allows us to compare the distribution of data between two variables. A JointGrid() makes use of scatter plots, regression lines, as well as histograms, distribution plots, and kernel density estimates to give us insights into our data.

2. JointGrid() Overview

The JointGrid is similar to the other Grid plots in that it takes a small number of inputs and creates an insightful visualization of the data. This type of plot may be new to many aspiring data scientists, so we will describe the basic layout. The input to JointGrid() is an X and Y variable. In this case, we are looking at the relationship between College Tuition and the Admissions Rate. The center of the plot contains a scatter plot of these two variables. The plots along the x and y-axis show the distribution of the data for each variable. This plot can be configured by specifying the type of joint plots as well as the marginal plots. Now that you know the basics, we can look at creating one.

3. Basic JointGrid

The JointGrid() creation process follows the same steps as the other grids. You must define the grid and map the plots onto the grid. In this case, we define the Tuition and Admission Rates as the X and Y variables. Then we map Seaborn's regplot() and histplot() to the grid. Seaborn takes care of creating the plot.

4. Advanced JointGrid

Here, we show the flexibility available through the JointGrid() function. The plot_joint() function specifies that a kde plot should be included in the center. The kdeplots on the margins are defined with plot_marginals().This view of the data helps us understand the distributions of data for these two variables. In this example, there is a large group of values that have tuition between $15,000 and $20,000 and admission rates around 60%.

5. jointplot()

The jointplot() is easier to use but provides fewer customization capabilities. In this example, we show a hex plot as the method to demonstrate the relationship between the two variables. As you can see, this is a simpler approach than creating the JointGrid().

6. Customizing a jointplot

The jointplot() supports simple creation of scatter, hex, residual, regression, and kde plots. It can also support adding overlay plots to enhance the final output. This example, shows a fairly common paradigm for analyzing the data with Seaborn. In addition to defining the X and Y variables, we set the limits for the x-axis to cut off at 0 and 25,000. We also pass keywords to the marginal plot to control the structure of the histogram. In this case, we only want to look at the distribution of results for public universities with an undergraduate enrollment less than 2,500 students. Finally, by including the plot_joint() function, a kde plot is overlaid on the scatter plot.

7. Customizing a jointplot

This combination of plots is useful for understanding the areas where Tuition and Admission rates have natural groupings.

8. Let's practice!

Now that we have discussed the JointGrid() and jointplot() functions, let's try creating some of our own.