Figure- vs. Axes-level Functions Video Lecture Transcript
This transcript was automatically generated by Zoom, so there may be discrepancies between the video and the text.
12:08:37 Hi! Everybody! Welcome! Back! We're continuing to learn about Seborn in particular.
12:08:42 We're gonna explain the difference between figure and axes.
12:08:46 Level functions. So hopefully, this is too confusing, because we haven't actually learned specific function types yet.
12:08:52 But I think it's useful to know the difference between the 2 main function types and seaboard before we dive into actual specific functions, like scatter, plot or line plot.
12:09:03 So why don't we go ahead? Let me clear my option first, and there we go.
12:09:09 So there's 3 main types of seborn plotting functions in terms of like the types of plots that they make.
12:09:18 So there are those functions that make relational plots. There are those functions that make distribution plots, and there are those function that make categorical plots.
12:09:27 So Seaboard has provided this excellent little diagram of sort of a hierarchy.
12:09:31 So there's the relational, the distributions in the categorical.
12:09:36 And then these are the plot types, like the function types that you can use.
12:09:39 So we saw an example of Scatterplot, where it will allow us to make a scatterplot in the previous notebook.
12:09:45 So that's a relational plot type. So you actually kind of see this hierarchy.
12:09:49 So what is the hierarchy? What does it mean?
12:09:51 Why is rel plot above, scatterplot, mind, plot, and do plot above his plot?
12:09:57 Kde plot. Ecdf. Plot and Rug plot.
12:10:00 Well, that's what we're going to learn about.
12:10:01 So, most, seborn plotting functions come in one of 2 flavors, so either a figure, level function, or an axes level function.
12:10:13 So remember when we learned about Matt plot lib that Matt plot lib has 2 sort of base classes that make up all of the plots.
12:10:22 There's the figure which holds everything. That empty window right and then there are the axes which is actually where you paint the stuff.
12:10:29 So you draw the graph. You make the annotations. So basically, the main difference between figure-level functions and axes-level functions are figure-level functions create and entire mat plot-lib figure, whereas axi-level functions just alter the content of a single axis mat plot
12:10:49 Lib, object, so figure level functions what they return is what's known as a faster grid object.
12:10:55 And we'll actually talk a little bit more about this.
12:10:57 I think when we we keep, when we move on to a later notebook.
12:11:03 But if you're interested in learning more about facet grid, you can see the downtown page here.
12:11:11 So basically, a facet grid is kind of similar to subplots where you're gonna have a oned or twod grid in order to compare different levels of a variable within the data set.
12:11:21 So as a quick example, we can use this plot so the ones at the top.
12:11:25 These are our figure level functions. We can use this to visualize something about the tips data set.
12:11:35 So why don't I actually go ahead and break this off as its own code chunk?
12:11:37 So we can actually see what the tips data set is.
12:11:41 So tips is the data set that takes in information about various bills tips, and then different features about both the worker and the time that they were working at arbitrary.
12:11:53 Okay. So for instance, we can see that this first restaurant worker, waiter was a female whose total bill for that table is 1699, and they received a dollar tip with one a dollar and one cent tip.
12:12:06 And this was on a Sunday dinner. Okay, so we're gonna go ahead and visualize some of this stuff.
12:12:11 So how about we do a display? And we do. My X is going to be.
12:12:16 And this is going to maybe look unfamiliar to you, which is fine.
12:12:20 What should look familiar. Right is this format of? I have a data frame.
12:12:22 So I put in the data, and then all of the other features I specify as column name.
12:12:28 So I'm gonna apply. I believe the default makes a histogram.
12:12:30 So I'm going to plot a histogram of the tip and then I'm gonna put an additional arguments like, I want my column, and this will be more clear.
12:12:40 Once we actually plot, I'm gonna have my column be the day of the week and the Hugh give me the sex of the worker, and then I'm gonna call plot show
12:12:57 Okay, so here is the example. So facet grid.
12:13:00 And this little grid allowed me to. This is a figure level function.
12:13:05 It returned this, that I'm seeing, which is a facet grid which now is showed histograms for the tip level.
12:13:11 So all the various amounts of tips, the histograms for the tip level on different days of the week, that this restaurant was open, and then stratified.
12:13:22 The tips based on the sex of the waiter.
12:13:24 Okay. And so just to show you what this is, returning this disk plot, figure-level function here is G, where I stored the output.
12:13:34 This is a facet grid. So this right here, this one by 4 grid of plots, is known as a facet grid object or clad an instant, an instance of a facet grid class.
12:13:45 So what else can we do to do so? I also want to point out this created a grid.
12:13:53 But you don't always have to create a grid.
12:13:54 So figure-level functions like, let's say we just wanted to look at the histogram of tips without any of these other arguments like sex and day, we can certainly do that as well using a figure level function like disc plot.
12:14:08 So this is the histogram of tips over the entire data set, not broken down into any subclasses or anything like that.
12:14:15 Okay, so figure level functions as a review, they create an entire map plot live figure in the form of a facet grid facet grids allow you to break off and make different types of plots based upon a categorical variable like day.
12:14:30 And we'll learn more about this as we continue on and learn these specific functions.
12:14:37 In a later notebook
12:14:39 So what are axes? Level functions, then? So axes, level functions allow you to just draw a patricular, a particular chart or graph type on a specific axis object.
12:14:49 So, if in this example I'm going to make a 2 by one grid using Plt subplots and then store the figure in the axes and these 2 variables and the 0 row of my grid I'm going to make a scatter plot using Matt plot lib so
12:15:06 We've seen this code before. And then in the one row of my grid, I'm going to go ahead and make the exact same plot, using Seborn.
12:15:15 So this plot plots the total
12:15:19 The bill on the horizontal axis, and then the tip, the tip on the vertical axis, and then the final argument that's gonna allow me to specify where this is plotted.
12:15:32 Is this a X argument? The ax argument takes in a mat plot, live axis, object.
12:15:39 So ax at one, and now I was going to specify that that's where that goes.
12:15:43 Okay, so this first one, this was the one made with this code.
12:15:46 The Mat plot list code, and then the second one was the one made with the Seborn code, which again, we'll I know I keep pounding it in the very next notebook.
12:15:54 We'll learn a little bit more about scatter plot.
12:15:57 So, as I mentioned, there's a hierarchy of functions.
12:16:01 So what do I mean by that let's return to this.
12:16:03 Is diagram. So you can see the functions rel plot, disk, plot, and cat plot are at the very top of the high hierarchy.
12:16:12 So these are the 3 fig level functions, and then beneath those are a variety of axes, level functions, so scatter, plot, and line plot, so scatter, plot.
12:16:22 We saw this example. Right? These are the axes, level functions in order plot is the figure-level function that can actually make either one of these plot types.
12:16:31 So that's the whole idea. Why are these ones at top at the top?
12:16:35 Because they can make for the most part can make every one of the one, every one of the plots below them, with the specific argument, okay, so this was the axes level version of the plot, the scanner plot.
12:16:50 And then, similarly, I can make a figure-level version of the same plot.
12:16:55 Using a kind argument equals scatter. And again, don't worry we're gonna learn about rail plot in the very next notebook in more detail.
12:17:01 Okay. So it's not exactly the same, because figure-level plots have a slightly different aesthetic than axes.
12:17:09 Level plots. But this is a plotting the same thing.
12:17:12 So you might be wondering what's the utility of using a figure level pot function versus an axis level function.
12:17:19 If I can just always make any plot I want with the figure level version.
12:17:25 So figure-level plots are nice because they allow us to make these grids based upon variable values.
12:17:31 So, for instance, this grid plotted the tips for different days of the week.
12:17:35 That's a nice feature. Another feature of the figure level plot is that the legends are placed outside of the plotting area, whereas for an axis level function.
12:17:47 So here's an example. Or maybe there's no example.
12:17:51 So, for the axes level function, you can see the legend is placed within the plot, whereas for the figure-level function it's placed outside of the plot.
12:18:00 So you know, it just depends on what your aesthetic is.
12:18:03 If this is the determining factor of whether you want you, you want the figure or the axes.
12:18:08 It just depends. Sometimes, figure levels are nice. Other times it's nicer to be able to have just a single axis level function.
12:18:17 Okay, so now that we have an idea of figure level functions versus access level functions, it's time to do it.
12:18:24 I kept promising throughout the first 3 notebooks is, we're gonna learn about these different function types.
12:18:28 We're gonna go in the order that Matt Plot Lib has presented them to us.
12:18:32 So relational plots first, then, distribution plots, and then finally categorical plots.
12:18:38 So the way these ones will work is, I'm gonna present. The function.
12:18:40 Tell you all about what it does tell you. The different arguments, and then move on to the next function, and as we keep going we'll see, like all the different little features of Seborn plots, and so you'll become familiar with them.
12:18:56 So we won't have to go as in-depth on the disc plots, and we won't have to go as in-depth, even even less so on the cat pots, because you'll have seen all the other stuff from the earlier videos so that being said I hope you enjoyed learning about
12:19:07 Figure level and axis level functions, and I hope you're looking forward to actually learning the specific functions.