Welcome back.
Now we're really going to step it up a notch.
We're going to see the full power of the map politely but object orientated method.
We're going to build upon what we've done here.
So we've created this this heart disease and cholesterol levels with our over 50s data frame.
But now we're going to add a subplot to this so we can visualize cholesterol levels and we might get
out over 50 data frame here so we can stop having to scroll up we're going to combine that with fell
act which is I'm not sure if I'm pronouncing that by the way either fell ash which is Mack's heart rate.
So we want to have a subplot where we've got cholesterol and fell patch on the y axis is but they're
both going to have age as the x axis.
So let's see that in action.
We want to title this subplot of coal age though which beautiful Well we want to go here.
We're going to recreate this we could copy and paste this code but again we want to practice writing
from scratch.
So let's see it in full force Fig.
We want to use the object orientated method.
Now if you've had a go at creating a subplot on your own.
This is the way you might have used but if not this is how I would create a subplot of these two.
So remember we want two different accesses.
So fig axe zero and ax.
This is gonna be ax one.
There we go.
So what this is saying is now we're creating a single figure but it's going to have two axes on it.
Remember axes are this year why in X where you can add data.
So let's use the same commanders before some plots.
And I want to end rows equals two.
We want in calls is gonna be one our previous figure size was 10 and six.
But let's make this ten and ten see what that looks like.
And now we want to go add data to ax zero.
Actually let's see what this looks like before we even plot fig size.
Oh we got an equal there beautiful.
So now we've got two blank canvases to start adding our data on here.
So we want to add data to access zero which is this one here so just gonna be this exact same as before.
We'll do something like this.
So now we're gonna add some data to access zero just like we've done up here.
We're gonna do something similar to this but again we're not copying pasting we'll do it from scratch
so we won't scatter equals ax zero dot scatter and we're gonna go X is going to be the over 50 age column
Y equals over 50.
And this is gonna be just a collateral column beautiful.
And then we're going to go see equals we're gonna color it with over 50 target column.
Now let's see what that looks like.
Beautiful we've seen this before.
So customize at 0 0 we want to go X 0 dot set and we want to add a title.
This is gonna be heart disease and cholesterol levels.
Wonderful.
And then we want an X label which is going to be age and then we want to go y label which will be cholesterol.
Nothing new here we've seen this before but now it's only on axis zero which is amazing.
Maybe we add at a legend to act zero same code as a four x zero dot legend scatter dot legend elements
and then we're going to go.
Title Eagle's target.
Beautiful.
What did we have up here.
We had a main line.
So that's what we can do with the hate line.
So add a main line.
So we're just replicating the plot we've done before axis zero dot.
Page line No we need to pass hate line of why so we want over 50s.
It's going to be a cholesterol.
So we'll do well dot main and then we'll add a line style as dash dash and that should be the same plot
as what we've got above.
But now it's on a subplot so I want to challenge you to before we go through it.
See if you can replicate what we've done here but with the foul ash column instead of the cholesterol
column on this subplot here I'll give you a second.
All right.
If you had a go.
All good.
If not let's go through it.
So now we want to add data to ax 1 because remember we've got X one up here.
Excellent.
Same thing we've done before but this time all we're going to do is change it from ax zero to ax 1.
And then of course the column will be different all the data that we use will be a little bit different.
So in this case it's 1 x the X is still going to be the age column.
What's going to change is what's on the y axis.
So we are over 50 now actually.
Wonderful.
Color is gonna be the same because we're focused on our target variable which is whether or not the
patient has heart disease.
So there we go.
Let's see what this looks like okay.
So we're starting to get somewhere now.
We've got some data on both our axis is let's customize it just like we've done with Axis zero.
And do that with x 1 x 1 don't set let's add a title title.
This one will be heart disease and max heart right.
Wonderful.
And then we're going to go X label.
Okay everyone that is just that age because we're using the same column for The X and the Y label.
This is gonna be fell act so we'll actually put in max heart rate because we want it to be a bit more
communicative than just that latch.
So if someone came and had a look at our plot didn't know what flash meant they'll know it means max
heart rate okay.
Standing graphics and progress.
Now we still have a couple more things to do.
We want a similar set up to what we've got here.
So let's add a legend to X1 axe one bolt legend.
Now again we're creating quite similar plots here with the subplot that we're making.
So these two are quite similar as you've seen before you could have a scatter plot here and you could
have a histogram here or something like that but we're just using this as an example.
So title ego's target wonderful.
Well I don't mean line as well.
So Ax one dot ax.
Page line now we're gonna color it with the Y is going to be this time instead of cholesterol it's going
to be all that wonderful dot main and then the line style we're going to keep it with our trusty dash
and then we'll add a semicolon here and let's have a look.
What have we messed up.
We got an error line today has no property line star.
This is classic typos everywhere.
Here we go.
So it's okay to make errors right.
You're never going to type out all the code correctly every time the first time beautiful.
This is starting to look really good.
Okay.
What we're starting to see we've got to age x axis label here but this is also age so maybe we could
tell them to share the X..
So let's say where can we add that maybe have in here.
I want to share the X so share X equals true
but now we can remove this label on access zero so what is this going to do if we put in share X equals
true.
What do you think.
There we go.
So what this is done is it's telling our plot to go that our subplots here have the same x value so
we don't need to put in the age label there maybe you would keep it in there for a bit more.
So it's a bit more communicative that's kind of one way you can start to clean up your plots.
And now what we might do is add a title to this overall things.
We've got both subplots are titled What we might want to title the entire figure.
So let's see how we do that.
Add a title to the figure.
Now this is big because remember we've created a figure and we've added data and customization for the
actresses but now we want to start to access the figure directly which is that big blue square on our
map plot level anatomy.
We filled up these two and our subplots.
Now we want a title our figure so we can do that with Fig Doc sup which he stands for I think it says
for Super title I actually don't know what some stand for.
I just know that it's subtitle and then we go.
Heart disease analysis and we'll create the font size we want it to be pretty big font size and a font
weight of bold and put a semicolon at the end beautiful.
Look at this.
Maybe we have to zoom out a tiny bit so we can see it all in one hit.
There we go.
Are you starting to see what this is kind of looking like.
Remember right at the start in the concept lecture we looked at the anatomy of a map plotted figure.
We looked at that plant and it was quite complex has a lot going on.
Well what you've done is you've just followed along and recreated something very similar.
Now what we're going to do in the next video is style this a little bit better so fix up some of the
colors.
The important thing to remember is it looks like a lot of code here and actually is.
We've got 25 30 lines of code there.
But what we've done is we've built this figure from scratch using the object orientated map plot lib
method.
And so now what seemed at the start to be a very complex and complicated plot is actually just quite
simple right.
You create a figure you create a couple of accesses you add data to the accesses you add some customizations
like titles and a legend in a horizontal line and you start to get something looking like this.
Now that's something that you can put in a demonstration or show your colleagues in a presentation something
like that right now you're starting to see just how powerful that plot lib object orientated API can
be.
All right let's wrap this video up have a practice maybe create your own subplot without a scatter try
a histogram and maybe a bar graph.
Can you do that on the same figure.
Otherwise I'll see you in the next video and we'll learn a little bit more customization of these plots.