Get Started

Building visualizations with Seaborn

1. Building visualizations with Seaborn

Now that you have some data acquisition and transformation tools let's build Python-based visualizations with the Seaborn package.

2. Plots with the Seaborn package

We will be building three plots - line plots,

3. Plots with the Seaborn package

pair plots,

4. Plots with the Seaborn package

and joint plots. These last two visualizations are built incorporating other basic plots, though the code is still a simple function! Let's walk through what those are and how to read them.

5. Histograms

A histogram is a component of a joint plot and sometimes pair plots. They highlight the distribution of a variable, in other words, the values it takes on and the count of observations with those specific values. The histogram we see here is referred to as “normal”. There is a larger count of observations within the middle values and smaller counts of observations with extreme values at the end.

6. Reading a histogram

Histograms can also be “skewed” when more observations are at one end of the distribution. For example, here is a right-skewed histogram.

7. Reading a histogram

And here is a left-skewed histogram.

8. Reading a histogram

A distribution can also be bimodal if two values have a larger count of observations. Here you can see that at 12 pm and 7 pm.

9. Scatter plots

Scatter plots are a component of both joint plots and pair plots. They highlight the relationship between two continuous variables by plotting one on the x-axis and the other on the y-axis. They are a great tool for quickly seeing the type of relationship between two variables. For example, when the data points form a random blob, the two variables have an extremely low or non-existent relationship.

10. Reading scatter plots

The relationship can be interpreted as stronger when the data points form a defined oblong or line shape. Likewise, the direction of the shape can tell if the relationship is positive or negative. Here we see a positive relationship; the data points form an oblong shape moving up and to the right. Said another way, as the x variable increases, so does the y variable.

11. Reading scatter plots

This relationship is negative when the data points form an oblong shape that is moving down and to the right. Said another way, as the x variable increases, the y variable decreases.

12. Joint plots

Joint plots marry these plots into one. One of the most common types is a scatter plot with a histogram on the top for one variable and on the right side for the other. This can be created with the seaborn dot jointplot() function, as shown in this slide.

13. Pair plots

A pair plot is an accumulation of plots into one visual showing the pairwise relationship between the variables in a dataset. It can be created with the seaborn dot pairplot() function taking a DataFrame as the required parameter.

14. Steps for building a plot in Power BI

Regardless of which plot you build with Seaborn in Power BI, each follows a general set of steps. First, we import the required packages. Power BI will require matplotlib dot pyplot to be imported, as we need this to render our plot correctly. Second, we perform any data transformation steps if needed. Fortunately, these have already been done in previous steps! If additional transformation is required, you may also need additional packages, such as pandas. Third, write code using the seaborn function for the desired plot. Generally, this will take a DataFrame as the first parameter. There may be a set of additional parameters for other plot components, such as the x-axis, y-axis, and hue. Fourth, use plt dot show to render in Power BI correctly! This is because Power BI requires a static image to be generated from the code.

15. Let's practice!

Let's see how all of this comes together in Power BI!