Facet Grids in Seaborn

Facet Grids offers a way to plot figures with lots of information. They are also known as lattice, trellis, or small-multiple graphics.

Let’s Explore Facet Grids with the help of a data set in seaborn and try to understand Facet Grid along with the data.

Lets Start with Loading Libraries

The seaborn data set we will be working with is exercise data set. It contains 90 rows and 6 columns. Good data set to work with for practice.

Explore the last 5 data entries of the data frame.
Shows the shape of the data frame.

Facet Grids

Let us now explore how facet grids are initialized. Here in an object called ‘g’ the Facet Grid is been initialized. The rows and columns of the data set will give structure to the grid. Here, only row parameter is used just to show what Facet grid does. The variable used is kind from the data frame. Kind here is : rest, walking and running.

Now, let us add column parameter of the facet grid and see the structure is ready in multiple axes. It is just like dishes are ready and now we have to serve the food! So, let’s do that..

The Facetgrid.map() function is used as a plotting function. This fills the grids with various plots and variables as specified.

Here, plot is scatter plot and it shows the pulse and diet plotted on x and y axis respectively. The rows specify kind of exercise, columns specify time the exercise is performed. sharex here will not share the x axis and we can easily see the pulse rates value for each graph.

Thus, we have plotted a facet grid with basic four information of the data frame. kind, time, diet( no fat , low fat), and pulse.

Another parameter HUE

Hue can be used to represent a third variable. This plots different sub-sets of data in different colors. Used for showing conditional relationships.Let’s see how it looks in this example.

Notice the difference between the above two plots. The first one plots the grid with columns and in the other one we do not require a column as hue is working fine in this case and showing us the same information as the above plot is showing.

Let us explore more plots now:

This time we will experiment with barplot plot of seaborn. Bar plots are used for categorical plotting. Use of palette to add more color robustness to the plots.

Let us plot a distplot of seaborn. Distplots are a combination of histogram and KDE. So, we can set KDE as false or true depending upon the plot we want. Here, the KDE is set as False and hence we obtained only Histogram.

Conclusion

The data provides us with information that people with no fat diet who work out for 30 minutes and the kind of exercise is ‘running’, have a high pulse rate as compared to other exercise like walking or rest.

The higher the pulse rate, the more strain on heart to pump in more blood to the muscles and lungs.

Now, we can go on saying that the person loses weight, remains fit and healthy, in shape. On the contrary, more strain on heart might also result to heart related problems.

Concluding Remarks

Facet grids helps to convey a lot of information in a single graphs. A single graph shows multiple sub-graphs. one can experiment with various plots and parameters to make the grid really interesting.

Thanks for Reading.

Leave a Reply