Axes Objects Video Lecture Transcript This transcript was automatically generated by Zoom, so there may be discrepancies between the video and the text. 13:46:32 Hi! Everybody! Welcome back in this video, we're gonna continue on with our Matt plot. 13:46:37 Lib. Content and learn about the axes, object so in the last video, we talked a lot about the figure object sort of the frame that's going to hold our art. 13:46:48 So in this video, let's talk about what the art is actually painted on. 13:46:52 So go ahead and go to the python. 13:46:56 Matt plot lib folders within the lectures, and then go you're gonna click on this one. 13:47:01 3 axes objects. I'm gonna click on this one. 13:47:04 Axis, objects complete. So remember the complete versions and the Notebooks will have the versions that I fill in from this video. 13:47:11 The other ones you can fill in on your own. So let's go ahead and go back to that very first map platform plot that we made in the last video. 13:47:21 The figure video, we can initiate a plot again with plot figure. 13:47:26 Then we go ahead and plot the line from negative 10 negative, 10 to 1010, and then we show the figure that we've created. 13:47:33 Okay, so here's our figure. Here's that pot. 13:47:36 So from our previous notebook, we know that this plot here the blue line, as well as well as the white box and the tick marks that it's sitting on all sit within or on top of a figure. Object. 13:47:51 So in the last notebook we talked about figure objects. 13:47:54 So what is like? What is the white box? And the line like? 13:47:58 What is this part call this is known as an axes, object, or an instance. 13:48:02 An instantiation of the axes class. So remember, when we created in the last notebook we created an empty figure, and we saw this when it came out. 13:48:14 Figure size, was 0 axes. So why are you seeing this? 13:48:17 Well, this is an empty figure that had 0 axes, objects. 13:48:23 So what command in this line created the axes? Object for our figure? 13:48:28 Why, it was plot dot plot. So when we called plot plot, what normally happens is we're asking our computer to draw a straight line from negative 10 negative 10 to 1010. 13:48:40 That's what this part's doing on the most recently created axes. 13:48:45 Object, however, in this example, when you start with Plt figure, there are 0 axes, objects. 13:48:52 So when you call applying function like plot, and your figure has no axes, objects on it. 13:48:59 Plot plot will then command to the computer, go ahead and create an axes, place it on this figure, and then I'll put this plot on there. 13:49:07 So calling, plot plot has created our faxes, and then, if we were to then call another instance of plot plot so negative, let's say we want to plot. 13:49:19 So the line going down with a slope of negative one. 13:49:23 Then it's gonna get plotted on that same axis because it was the most recently created one. 13:49:28 Okay, so going through the code, we first created our figure. This first call to plot created the axes object which contains, like, was all this stuff was drawn on top of so sort of think of the box itself as the axes like a canvas, or a piece of paper and then all the stuff we're 13:49:47 drawing as the art, so like. Here's the, I imagine. 13:49:51 I painted this blue line that's what happened with this first bit of code. 13:49:56 Then the second call to plot notice that there was an axes on the figure, and then went ahead and plotted this orange line on top of the axes, and then once again plot show just shows us the whole thing. 13:50:10 We just created. So you know, that's one way to do it. 13:50:13 But sometimes in when you're making a figure, you're gonna want to have more control over the axes that get added to your plot, there's a number of ways you can do that. 13:50:22 So the first way we'll talk about is this function. 13:50:24 Add, subplot. And here's the link to the documentation here that you can look at. 13:50:30 So for add subplot. The first thing you do is you create your figure, then you go ahead and you call Plt. 13:50:36 Dot, add so plot, parentheses, and then, when you run this, what's oh, sorry not plt dot apps so add so flat fig dot, add subplot, so add subplot requires a figure. Object. 13:50:52 It's a method, a class method of the figure class. 13:50:55 So you do fig, Don, add subplot. And now this figure, which was empty, has an access, an axes object, and it's this blank white square. 13:51:10 So I wanted to also point out, you can notice here before we just called these things, and then didn't store it anywhere here we're storing things in a variable. 13:51:20 So we're storing our figure in the fig variable. 13:51:24 And then the axes we've created on top of or within that figure in the A X for axes. 13:51:29 Variable. Okay? So now that there's certain variables, we can actually, we can actually reference them any other time within the notebook. 13:51:37 So let's say, now I want to say, Oh, I have this empty axes. 13:51:42 I want to plot something on it. I can call ax, which is the variable that contained the axes and dot plot, and then that will plot on top of that axes 13:51:53 Okay. 13:51:57 So what are some other ways to add? Axes? There's 2 additional ways that you can add an axes with a specific command. 13:52:04 The first is, add axes, and within that you have to put in a rectangle that will specify like where within the notebook that you're going to add it. 13:52:14 So here's an example where I create my figure. And then I add, one axes object. 13:52:20 So I call add axes, and then within this I specify the rectangle. 13:52:26 So I want to go from 0 comma 0 up point 2 5 units of the figure. 13:52:34 So like a quarter of the figure, and then to the right, a quarter of the figure, so the first 2 entries within your list, or array or tuple, are the Xy positions with respect to like where it is on the figure of the bottom left hand, corner of the axes 13:52:53 And then this will go. Tell it. I believe the first entry is how far right it goes, and then the second entry is, how far up it goes. 13:53:00 So the width and the height and now I add a different axes. 13:53:05 This one will be in the upper right hand corner 13:53:10 And then I add a final axes. Now this one will also be on the right, but now it'll be in the bottom right corner 13:53:17 Okay. Now, we can see that in the figure we can examine, like, what would happen if I change the position. 13:53:24 So let's say I go to figure 2, and I change it into. 13:53:27 I'll keep it at. Let's say, let's do point 3, but I keep it at point 8. 13:53:32 And now axes 2 is moved over here. Okay, so you can go ahead and explore the rest of this stuff on your own by going to the documentation so you can click on it. 13:53:44 And you can see like, what are the things that I need to explore. 13:53:46 So here's this is telling us what we need to do for the rect. 13:53:50 And then there are other options that maybe you're interested in. 13:53:54 Okay. 13:54:00 So what do you get with an axes? Objects? You get quite a bit. 13:54:05 So what you see are these white squares which we can plot on? 13:54:09 But you can change a lot of stuff about these axes so you can change the axes that we see. 13:54:16 You can change the outline of the rectangle we'll talk more about this in a later notebook. 13:54:20 There's the background of the rectangle, which you can also change. 13:54:24 You can change the appearance of the tick marks. How many tick marks there are, whether or not there's something called minor tick marks. 13:54:31 You can change the labels of the tick marks, you can change the title on top of each axis. 13:54:36 You can change the axis titles within each axis. 13:54:40 So there's a lot of stuff you can change. So here's an example where I go ahead and use a function that's gonna allow me to change the label. 13:54:50 So of the X and y axis axes on the axis object so that that gets confusing. 13:54:56 So we'll say, X label. And I'm just gonna call it X, and don't worry about the like. 13:55:01 Some of the code. So like, maybe you don't know what X label is. 13:55:04 We're gonna talk more about that in a later notebook. 13:55:07 This is just sort of demonstrating, demonstrating what you can change about an axis object. 13:55:15 So now there's y label, and then that I'm going to say, all right, I wanna label this Y, so now we have our our plot that we've been working with for now the horizontal axis of the axes object has a label called X the vertical 13:55:29 Axis of the axis. Object has a label called Y. 13:55:33 Another way to do this is with the function you can appeal to the acts like the axes object itself. 13:55:39 So you call ax, because my axes here is stored within the variable ax. 13:55:45 So you call ax and instead of X labeling, do set X label and we'll do the same label here, and then you can also do set y label, and then once again, this will be why, okay, so the same image. 13:56:01 But 2 different ways to create it. So making adjustments like this to non graphical plot elements is a big part of data visualization is just as important as like the the graph elements. 13:56:15 So the lines are the points or the bars. Good labeling and good plot. 13:56:21 Aesthetics are really important. Part about data visualization. 13:56:23 So much so that we're going to have it's it's gonna have its entirely its own. 13:56:28 Jupiter, Notebook. Later in this section so don't worry about we didn't cover like set X label or X label in depth. 13:56:37 We'll talk more about these in a later notebook. 13:56:39 So now you have a good foundation of like what Matt plot live creates. 13:56:44 It creates a figure object, and then, on top of that figure object we have axes, objects you can have more than one. 13:56:50 We're gonna learn more about these as we continue to move along these notebooks by necessity, and then we'll also have specific notebooks where we learn specific things about axes, objects and the figure objects as well. 13:57:04 So I hope you enjoyed learning about axes, objects getting introduced to them? 13:57:08 We're gonna work with these quite a bit, because they're what we paint. 13:57:11 Our graphs on top of I hope you enjoyed this video. 13:57:15 I enjoyed having you watch this video, and I hope to see you next time.