‫Welcome back.
‫In the last video, we checked out a few different methods of creating map plot, lib plots and figures.
‫That name is kind of interchangeable.
‫Same with the name visualisation if you hear that they're often referring to the same thing.
‫And we looked at a little trick with the little percentage sign to set up map plot lib so that our plots
‫appear in our Jupyter notebooks.
‫So now we're going to start this video off by checking out the map.
‫Plot Lib Anatomy of a figure.
‫So let's have a look.
‫As I just said, I've got anatomy of a map plot, lib plot.
‫And I just said, we're going to check out the anatomy of a figure.
‫And so this is how I mean, these words are very interchangeable.
‫So I want you to be aware of that whenever you're looking at that plot lib online.
‫If you go into StackOverflow or whatever resource, the documentation probably is more formal using
‫the word figure.
‫We'll see that in a moment.
‫But it refers to plot or visualization.
‫There always meaning kind of the same thing, which is this complicated but beautiful mess here.
‫So if we look at it, figure is kind of like the giant.
‫Section here, the everything, the blue square.
‫So the figure contains all of it.
‫It's like the blank canvas.
‫And then what we're going to do is start to add things as we go to make our plots look beautiful.
‫So we've got some data here.
‫This is heart disease analysis.
‫This is the center title.
‫Don't worry if this looks a little bit more complicated than the plot we've just done.
‫Like this is a very simple plot here.
‫This one's got a bit of fancy colors and a horizontal line and titles and legends.
‫We're going to work towards making something like this, but by the end of the section.
‫So we'll get there in a moment.
‫But you can see here these two axes, this is a subplot.
‫We've got one plot here, actually zero.
‫And this is axes one.
‫So there's two types of information here.
‫But they share an x axis, which is the age.
‫We've got an x axis label here.
‫We've got axis one title.
‫This one's got a legend.
‫So does this.
‫And then we've got two different Y axes label.
‫So this one is max heart rate and this one is cholesterol.
‫And then we've got a main line going through here.
‫You might want to take a screenshot of this, but don't worry, it'll be in the resources section.
‫This is kind of the anatomy of most map plot lib plots that you'll check out, at least for 2D plots
‫anyway.
‫So yeah, you've got label titles and what all these little things do is that they just add to the communication
‫value.
‫Of course, you could make a plot without these titles or these horizontal lines or these fancy colors,
‫but it would be kind of hard to understand.
‫So that's why we add these things here.
‫Let's go back.
‫Before we jump into the next video, let's have a little bit of a look where the object oriented comes
‫from.
‫So if we go back to this cell here, we might go type, fig type.
‫X.
‫So here we go.
‫We've got map plot, labor figure, figure.
‫So the formal definition for something like this is a figure.
‫And then we have map, plot, clipped axes, subplots, axes, subplot.
‫So this is what it means when map plot lib talks about the object oriented API.
‫So we've got the figure object, which is back to our anatomy.
‫This is the figure object here, this big blue square.
‫And then we have the axes, objects, and now the axes objects.
‫They're always kind of a subplot because this is a subplot on a figure.
‫But you can have more than one axes on a figure, if that makes sense.
‫So if we had two more of these over here, this blue box would stretch out to cover those.
‫So the figure is the base canvas and the axes are like, we're drawing on that base canvas.
‫Now that we've kind of understood the fundamentals of that plot layer with the figure and the axes,
‫let's check out a workflow in in its entirety.
‫So we'll type in here map, plot, lib, example, workflow.
‫I will make this a heading so it's a little bit separate map plot lib example workflow.
‫So step zero is import map, plot lib and get it ready for plotting in Jupyter.
‫Beautiful.
‫Now, we've already done this, but I would just want to do it all in one cell so you can see it happening.
‫Map Plot lib inline import map plot lib dot pi plot as plot.
‫Step one is to prepare some data.
‫Prepare data x equals.
‫We'll keep it nice and simple just as we did before.
‫But you'll see in reality, X and Y can be basically any data or any numbers that you can imagine.
‫And then we're going to number three.
‫We're getting ahead of ourselves here.
‫Set up plot.
‫Now this is where we use the object orientated method.
‫Figure X equals plot subplots.
‫We're going to throw in a little keyword here that I want to introduce you because you'll see this a
‫lot.
‫Fig size 1010.
‫Now let's see what this means.
‫Can we go shift tab?
‫Yes, we can we go down?
‫Is it going to have it there?
‫Oh, it might not.
‫Fig size parameters.
‫We'll keep scrolling through here.
‫It's a bit hard to see.
‫Fig size axe examples.
‫Well, I'll just tell you what it is.
‫Well, you can practice looking at the documentation, but what this essentially means is it just height
‫and width and they may be back the front, it's usually X then Y.
‫So this is probably width and this is probably height.
‫That just means the dimensions of this plot.
‫So we'll go here.
‫And we'll go number three, which is plot the data.
‫So we want to add to our X, X and Y.
‫What have we done here?
‫We've created a figure and we've created an axes.
‫And now what we're doing is adding data to our axes.
‫Okay.
‫Yeah, this is making sense for.
‫And then we want to customize plot.
‫Now we haven't seen these, but they're fairly intuitive, so I'll let you guess as I'm typing them
‫out.
‫Simple plot.
‫That's a good title.
‫I think what they actually mean.
‫So now that we've we've done just one, what do you think we've got so we've got ax set and then a parameter
‫saying title equals simple plot.
‫Hmm.
‫X axis.
‫We'll keep the titles for the x and y, nice and simple y equals y axes.
‫Wonderful.
‫And then we'll go number five.
‫You probably wouldn't usually do this.
‫I'm just showing you all this in one hit, just for the sake of seeing a map.
‫Hollywood workflow, running lav.
‫Save the whole figure.
‫That's the word I'm looking for.
‫That's what I said out loud.
‫But that's what I didn't type.
‫So fig, dot, save fig.
‫And then we want to save it to.
‫I've got an images folder set up that I already have prepared earlier, so you can save it wherever
‫you want.
‫But this is just going to be the path name sample plot.
‫PNG.
‫There we go.
‫So let's step through this.
‫We import map pop lib.
‫We tell Jupyter that we want to plot our map, plot lib plots in line or figures in line.
‫So within the notebook we've created some data X and Y, we've set up a plot a.k.a a figure.
‫We've given it a size of ten by ten.
‫We've added some data to the plot on our axes, and then we've customised the plot.
‫Now, can you guess what's going to happen here?
‫If we look at this, then if we compare it to our anatomy, we've got a title and we've got X and Y
‫labels.
‫Can you guess what this is going to do here?
‫We'll see in a sec.
‫Remember, if in doubt, run the code and then we're going to save a figure here.
‫We could share it out like that.
‫Let's see what this does.
‫Oh, we got an error.
‫That's all right.
‫No such directory.
‫Ah, that's alright.
‫I thought I knew the path of my image directory.
‫Doesn't really matter.
‫Images.
‫What have I got wrong?
‫Images.
‫Ah, I don't think I need the dot.
‫Dot?
‫There we go.
‫Simple plot.
‫So this is a ten by ten figure.
‫So let's practice this.
‫Maybe we change this to five.
‫Okay.
‫Yeah.
‫So that was width.
‫So this is.
‫Width.
‫Height.
‫Beautiful.
‫There we go.
‫Well, that's not looking very good.
‫So let's put that back to ten.
‫Wonderful.
‫And so now we can see the title is Simple Plot.
‫The Y label is y axis and the x label is x axis.
‫Of course, if you had some data on here that was more specific, you might want to label your x and
‫y axis is to tailored to your data.
‫But in our case, this is just a nice and simple plot as we've got the title here.
‫And if we go back up here checking our images folder, we've got sample plot PNG, which if you didn't
‫want to write this line of code, you can also right click and go save image as but that is enough.
‫You've seen a map of workflow.
‫You've also seen the anatomy of a map, plot, lib, plot or figure.
‫So before the next video, try to create your own plot like this.
‫Get as fancy as you like.
‫Create a little bit of data.
‫You could try create an umpire ray and plot it and see how you go.
‫Otherwise, I'll see you soon.