‫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 method.
‫Now there is no real definitive answer here.
‫The documentation on that plot will push you towards the method.
‫Always.
‫However, when plotting something quickly.
‫Okay to use the pie 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 pie plot method that we've gone through in
‫the last couple of videos.
‫But when plotting something more advanced, use the old method.
‫So we're going to 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 want to see the distribution of a column.
‫It's perfectly okay to go plot.
‫But now we'll see the method in action.
‫Let's create a subset of our dataframe 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 and we want to create a little bit of a plot and start to do
‫some data analysis on those.
‫So we'll create another dataframe called over 50, which is equal to our heart disease dataframe, which
‫we'll get a little refresher here so we know what it looks like.
‫This is the kind of workflow you'll be going through is looking at your dataframe and going, okay,
‫my colleague or my teammates and my boss want to know what's 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 at our over 50 data set.
‫What have we got wrong here?
‫A key error.
‫I've used a capital II.
‫That's all right.
‫Wonderful.
‫And we might check the length of this.
‫208.
‫So we have 208 versus about 300 or so of the original data set.
‫So that's fine.
‫Don't head wonderful.
‫And again, we've dropped out these two rows, so 3741 using our Boolean indexing.
‫So now it goes 03456 but the rest of the columns are still the same.
‫How about we start with a scatterplot 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 of equals scatter.
‫And then we want x equals age and then we want y equals we want the cholesterol column, which is this
‫one here ch0l is short for cholesterol and then we want to cover it using the C.
‫So C is short for color by the target column.
‫So we want plot kind scatter.
‫Yes, that makes sense.
‫Ex age y cholesterol.
‫Cholesterol.
‫Kind of a hard word to say see oil 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 Chao on the wall.
‫That makes sense.
‫X doesn't really show us much, and C is giving us this colour bar to show us that.
‫Because Target has values of zero one for 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 they're a target value of zero or one, but it doesn't show us anything on the x axis and these colours
‫aren't really that great.
‫So let's spruce things up a little and how can we do that with the method?
‫So this is the pie plot method a.k.a plotting directly from pandas data frame with plot.
‫Now let's do our own method.
‫We're going to recreate this.
‫But using the old method.
‫So let's go.
‫Fig AX.
‫We've seen this before, pelt subplots and we might go fig sighs just to have some practice adjusting
‫the size of our figures.
‫And we'll go 10/6 We want a width of ten and a height of six.
‫These are in inches, by the way.
‫I believe so over 50 plot.
‫Now this is going to look very similar to what we've done up here.
‫But there's one slight difference.
‫Kind of eagles scatter.
‫Wonderful.
‫Now we could copy and paste, but we're not going to do that because we're in the habit of writing out
‫code y equals chore or cull.
‫See, we use the Target column as color.
‫And then the last part is the ax parameter.
‫So when we're using the old method with pandas, the plot function gets this ax parameter.
‫Tell us, Hey, we're using the old method and we want you to plot this data.
‫On this axis, the one we've just created.
‫So let's see that in action x, we'll 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 big arc because we've put the fig size parameter in there, and now because we've passed the
‫X 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 and it goes ten six.
‫We still don't have the age X label there.
‫Well, the O 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 dataframe.
‫So let's have a look what that looks like.
‫We're using the O method.
‫We can access the axis here.
‫And 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 a shift tab, but I want you to just have a think about it.
‫So x set x lim 45 100.
‫So that's alright if you didn't get it, if you press shift tab and read it, you cheat a little, that's
‫all.
‫So fine.
‫That's actually a good thing to do is start exploring what Shift 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 you see how we've got, like a lot more white space 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 giving an example of how you could quickly adjust the the limitations of your accesses if they
‫don't look too good.
‫But that lib is generally pretty good at creating access 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.