Well welcome back.
It's the last video we left off saying that this plot probably isn't ideal.
We've got a few subplots going on here and we've been using the PI plot method plotting directly from
a panda's data frame rather than the object orientated method.
And I'm sure you're wondering you're going.
Daniel you've introduced so many different ways of plotting and you're telling us there's two ways of
doing it.
And you're saying one is less ideal than the other.
Which one should I use.
And that's a perfectly great question.
So which one should you use pi plot this map plot lib o method now.
There is no real definitive answer here.
The documentation on that plot level will push you towards the O method always.
However when plotting something quickly okay to use the PI plot method.
Right.
So what we've seen up here when you want to get a quick visualization maybe not something like this
but definitely something like this.
It's okay to use the PI plot method that we've gone through in the last couple of videos.
But when plotting something more advanced use the O method.
So we're gonna see an example of that in this video.
Something a little bit more advanced than just something singular like this.
But if you're just making a quick plot like this you just wanna see the distribution of a column it's
perfectly okay to go dot plot.
Now we'll see the O method in action.
Let's create a subset of our data frame so we can do a little bit of data analysis.
Let's say we wanted to explore the patients which are over the age of 50.
We only wanted to look at those patients.
We want to create a little bit of a plot and start to do some data analysis on those.
So we'll create another data frame called over 50 which is equal to our heart disease data frame which
will get a little refresher here.
So we know what it looks like.
This is a kind of workflow you'll be going through is looking at your data frame and going okay.
My colleague or my teammates and my boss want to know what some data analysis of our patients which
are over 50.
So let's do that we can access those by using boolean indexing.
So we want heart disease.
Actually we want to use the age column which are greater than 50.
Wonderful.
And then we want to have a look it out over 50 dataset.
What have we got wrong here.
Age Kiara I've used a capital I.
That's right wonderful.
And we might check the length of this 209.
So we have two hundred and eight.
This is about 300 or so of the original dataset.
So that's fine.
Go ahead.
Wonderful.
And again we've dropped out these two rows.
So 37 41 using our boolean indexing.
So now it goes 0 three four five six.
But the rest of the columns are still the same How about we start with a scatter plot of The Age and
cholesterol but we want to color it with the flavor of the target column.
Well that's a lot going on there.
Let's see the code first and then we'll figure it out from there.
Over 50 dot plot kind equals scatter and we want X equals age and we want Y equals.
We want the cholesterol column which is this one here C H O L is short for cholesterol and then we launch
to cover it using the c So c is short for color by the target column.
So we won't plot kind scatter.
Yes that makes sense x age y call or child cholesterol kind of a hard word to say see agile and the
color is target.
Let's see what happens all right.
So we can kind of see what's going on here.
We've got Charles on the Y.
That makes sense.
X doesn't really show us much.
And C is giving us this Calabar to show us that because target has values of 0 1 4 if someone does have
heart disease or they don't.
Does this look okay to you.
To me it doesn't look very good.
It's doing what we want it to do.
It's got different dots on here.
If their target value of 0 or 1 but it doesn't show us anything on the x axis and these colors aren't
really that great.
So let's spruce things up a little.
And how can we do that with our method.
So this is the pipeline method a.k.a. plotting directly from the panda's data frame with plot.
Now let's do o method.
We're going to recreate this but using the O method so let's go fig act.
We've seen this before.
BLT dot subplots and we might go fig size just to have some practice adjusting the size of our fingers
and we'll go 10 6.
We want a width of 10 and a height of six.
These are in inches by the way I believe so over 50 dot plot.
This is gonna look very similar to what we've done up here.
But there's one slight difference kind Eagles scatter.
Wonderful.
Now he could copy and paste but we're not going to do that because we're in the habit of writing out
code Y equals charcoal or coal.
See we use the target column as hell off and then the last part is the ax parameter.
So when we're using the O method with panders the plot function gets this ax parameter tell us hey we're
using the O method and we want you to plot this data on this axis the one we've just created.
So let's say that an action ax would put a little semicolon at the end beautiful.
So what we've done is we've recreated the same plot but it's already looking a little bit better.
It's a bigger because we've put the fig sized parameter in there and now because we've passed the ax
method we've now got this age column which has been labelled beautiful actually we might give this one
a chance and say hey let's up this fig size and see if it does the same thing 10 6 we still don't have
the age X label there.
Well the 0 method is already pulling out ahead.
Now what we might do is we set the X limit to be a bit wider so we can have more space on our data frame
so let's have a look that looks like we're using the 0 0 method we can access the axis here.
Remember the Axis is just this space that we're plotting data on if we go back to the figure of our
anatomy of a map plot lib figure or plot axis.
Is this part here where we're adding data.
Whereas figure is the entire thing.
So let's go back we want X dot set X Lim to be 45 100 can we figure out what this does before we even
look at it.
So set X Lim We could do shift tab but I want you to just have a think about it.
So Ax set X Lim 45 100.
So that's right.
If it didn't get it if you press shift tab and read it you cheat a little.
That's also fine.
That's actually a good thing to do is start exploring what Chef Tab does but this is going to change
the limitations of our x axis to be from 45 to 100 instead of what it is now which is about 50 to 80.
So let's see what happens so see how we've got like a lot more whitespace over here now because we've
upped the X limit but if we didn't want to do that we could comment that out and that looks a bit better.
Just given an example of how you could quickly adjust the limitations of your accesses if they don't
look too good.
But lib is generally possibility good at creating axis limits that are suited to whatever data that
you're using.
Now this plot is okay but it definitely could look nicer.
So this black and white is kind of hard to get this color bar is not really offering much at all.
So let's take a little break there and in the next video we'll make this plot look a little bit nicer
and we'll build off what we've already done here.