Python Data Visualization Transcripts
Chapter: Seaborn
Lecture: Displot

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now let's go through and show how to use Seaborn to plot some data. I've gone ahead and created a new notebook to load in the data and get everything
0:09 in our pandas data frame and I'll just walk through that real quick. So I have my imports and as I mentioned I have Seaborn as sns I am
0:18 now reading in the summary EPA fuel economy file that I referenced. And you can see that I have a few new columns here.
0:27 I have a date range, I have fuel type summary, I have class summary, I have the transmission so I have additional columns that I
0:39 will use for the analysis. First thing I'm going to do is show you how to set a style when you set a style.
0:47 Nothing is apparent yet. But let's go ahead and do our famous histogram and we're going to start that using a dis plot and now we have the history
0:57 graham. If you want to see what the styles do, let's change this to white grid and we'll rerun it and you can see that.
1:08 Now it's a white background. So I'm gonna stick with dark grid but you can use whatever one you want for your own visualization.
1:18 I'm gonna go ahead and restart and run all again just to get us all on the same page. Okay now let's go through a little bit more about how this
1:28 dis plot works. So I'm going to copy this. And really the best practice is to say that data equals DF. And then I can specify the kind.
1:40 So let's specify that we want to do a KDE. And now we'll get that smooth kernel density estimate.
1:52 Another one that's kind of interesting to do is the empirical cumulative density function. And this just tells you that at,
2:06 let's say around 22 MPG, that's around 80% of the samples fall into that range or less. And then to get in that nineties,
2:19 you've got to go up to call it 40 or so. So this can be useful to see what that that total trend looks like.
2:26 One of the other plots that we talked about was a rug plot. So let's just do a KDE and rug equals true. And now we have this rug plot at the bottom.
2:39 So as you can see the displot allows you to do many different kinds of plots by specifying the kind and other parameters.
2:50 Now, let's talk a little bit about, remember I talked about figure and axes levels plotting in seaborn. So I'm gonna bring back up a histogram.
3:01 But this time I'm going to use hist plot. You'll see a hissed a gram that looks not that dissimilar from our displot.
3:13 And now I'm gonna zoom back out a little bit. So you can see them both. I realize it will be a little bit smaller,
3:18 but I want to show that both plots are essentially the same. This one is taller and this one is wider.
3:26 But the interesting aspect I wanted to point out is that you can see that this is an axes subplot and this is a Seaborn object.
3:36 If I actually just write type around this to tell us what type it returns, see how it returns a matplotlib,
3:44 axes here, it returns a Seaborn facet grid object. So this is the distinction where behind the scenes,
3:56 the displot actually is using a lot of the same underlying code as the hist
4:02 plot, but it's returning it to a different type of object and we'll talk about
4:08 why we want to use that facet grid object that's returned to do more complex visualizations.

Talk Python's Mastodon Michael Kennedy's Mastodon