Welcome back.
In the last video we checked out a few different methods of creating that plot.
Live plots and figures.
That name is kind of interchangeable same with the name visualization.
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 Jupiter notebooks.
So now we're going to start this video off by checking out the map plot lib and anatomy of a figure
so let's have a look.
As I just said I got anatomy of a map plot lib plot and I just said we're going to check out the anatomy
of a figure.
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 live online.
If you go in a stack overflow or whatever resource that 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 sort of 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.
This is a very simple plot here.
This one's got a bit of fancy colors and a horizontal line 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 axes one tidal wave.
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 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 live 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 thing type
so here we go.
We've got map plot libbed figure dot figure.
So the formal definition for something like this is a figure and then we have map plot lib dot axes
dot subplots to access subplot.
So this is what it means when that plot labor 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.
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 map plot layer with the figure and the accesses.
Let's check out a workflow in its entirety.
So we'll type in here map plot lib example workflow.
Make this a heading so it's a little bit separate map plot lib example workflow.
So step 0 is import map plot lib and get it ready for plotting in Jupiter 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
that partly inline import map plot lib dot higher plot as P L T 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 will go to number three we're getting
ahead of ourselves here.
Set up plot.
Now this is where we use the object orientated method.
Fig ax equals P LTV dot subplots.
We're gonna throw in a little keyword here that I want to introduce you because you'll see this a lot.
Fig size 10 10.
Now let's see what this means.
Can we go shift tab.
Yes we can.
We go down.
Is it going to have it.
It might not figure size parameters.
We'll keep scrolling through here.
It's a bit hard to see excise acts.
Examples.
Well I'll just tell you what it is.
Oh you can practice looking at the documentation but what this essentially means is it just height and
width and they may be back to 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 get here.
Then we'll go to 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 the 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 plots.
Now we haven't seen names 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 we've got X dots set and then a parameter
saying Title X equals simple plot 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 to 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 plotted workflow running live save the whole figure.
That's what I'm looking for.
That's what I said out loud but that's what I didn't type.
Fig.
Don't save Fig.
And then we want to save it too.
I've got the 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 pot lib.
We tell Jupiter 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.
Okay a figure we've given it a size of 10 by 10.
We've added some data to the plot on our axis and then we've customized 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 we've got X and Y labels.
Can you guess what this is going to do here.
We'll see in the second member 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.
We got an error.
That's all right.
No such directory.
That's right.
I thought I knew the path of my image directory doesn't really matter.
Images.
What have I got wrong.
Images.
I don't think I need the dot dot.
There we go.
Simple plot.
So this is a 10 by 10 figure.
So let's practice this maybe we change this to 5 Okay yeah so that was width so this is width quite
beautiful.
Oh yeah well that's not looking very good so let's put that back to 10.
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 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 check in our images folder.
We've got sample plot dot Peng G 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 hotly workflow.
You've also seen the anatomy of a map plot leave a plot or figure.
So before the next video try to create your own plot like this.
Get his fancy as you like create a little bit of data.
You could try create an umpire and plot him see how you go.
Otherwise I'll see you soon.