Get startedGet started for free

Introduction to Seaborn

1. Introduction to Seaborn

Welcome to this introduction to Seaborn. My name is Chris Moffitt and I will be your instructor for this course. I have been using Python for over 10 years and am currently the creator of the popular blog Practical Business Python. I am excited to show you how to effectively use the Seaborn library for creating insightful visualizations.

2. Python Visualization Landscape

The Python visualization landscape is complex and it can be challenging to find the right tool for the right job. Before we discuss Seaborn in detail, it is helpful to understand where it stands in this landscape. This illustration is from Jake VanderPlas' pycon 2017 presentation on the visualization landscape in Python and highlights the complex ecosystem. The key point is that matplotlib is a foundational library used by many visualization tools including Seaborn.

3. Matplotlib

matplotlib is a robust library that can support building many types of visualizations. Seaborn uses it to construct statistical visualizations. When working with Seaborn, it is helpful to understand some of the underlying matplotlib constructs. This brief example shows how to plot a column in a pandas DataFrame as a histogram. This specific example includes information about the alcohol content of several different types of Portuguese wines. If you do not understand this code example, you may want to review some introductory Python courses. The rest of this course will assume you understand basic Python and pandas usage.

4. Pandas

pandas is one of the most important Python libraries for manipulating and analyzing data. In addition to providing powerful data manipulation tools, pandas supports basic data plotting functions. The actual API is consistent with other pandas functions, so it is a very useful tool. The plotting is carried out by matplotlib, so the resulting output looks very similar to the pure matplotlib output. This functionality is very useful when you need to quickly look at data that is already in a DataFrame.

5. Seaborn

Seaborn integrates with the rest of the Python data science landscape by leveraging matplotlib and integrating with pandas. In this example,

6. Seaborn histplot

a plot similar to the pandas histogram can be created using Seaborn's histplot() function. The resulting output is a histogram. Seaborn also supports other types of distribution plots such as a Kernel Density Estimate or KDE. In an upcoming slide we will compare this output to the pandas generated histogram.

7. Seaborn displot

Seaborn frequently has functions that have similar capabilities. In the previous slide, we used histplot to create a histogram. A displot can create a histogram as well as other plots such as the KDE plot shown here.

8. pandas Histogram vs. Displot

This relatively simple example is illustrative of how to use Seaborn. The code is simple but can be used for powerful data analysis. In addition to the analysis, it makes reasonable assumptions about colors and other visual elements to make visualizations that look more pleasing than the standard matplotlib plots.

9. Let's practice!

Now it's your turn to try out Seaborn.