1 00:00:00,270 --> 00:00:01,500 Welcome back. 2 00:00:01,500 --> 00:00:06,310 So in the last video we saw two different ways of plotting from a panda's data frame. 3 00:00:06,480 --> 00:00:07,980 One with the PI plot method. 4 00:00:08,340 --> 00:00:14,010 And we created this plot here and then the other with the object orientated method. 5 00:00:14,010 --> 00:00:21,180 I'll be honest with you this is not directly the O method we've kind of passed it off here but we're 6 00:00:21,180 --> 00:00:23,960 still kind of using the PI plot method here. 7 00:00:24,030 --> 00:00:27,280 But we've tricked it a little in combining it with our method. 8 00:00:27,750 --> 00:00:34,230 So what we're going to do is recreate this but using the object orientated method from scratch and we're 9 00:00:34,230 --> 00:00:37,260 going to customize it to make it look a bit more prettier. 10 00:00:37,410 --> 00:00:43,910 Let's start we'll create a new figure and a new axes will put in here. 11 00:00:44,290 --> 00:00:52,570 Our method from scratch and up here we might go our method mixed with pi. 12 00:00:52,570 --> 00:01:00,760 Plot method so then we'll go plot dots subplots and we know our fig size. 13 00:01:00,760 --> 00:01:05,480 This is a pretty good size so we're going to we're going to reuse that 10 6. 14 00:01:05,530 --> 00:01:06,220 That was correct. 15 00:01:06,220 --> 00:01:07,400 Yep. 16 00:01:07,660 --> 00:01:12,710 And then we want to do plot the data because that's part of our map plot workflow. 17 00:01:12,790 --> 00:01:18,850 We'll call our figure we'll rename it to scatter we'll go scatter equals x dots scatter. 18 00:01:18,880 --> 00:01:24,280 Because we want to scatter plot and we're going to go X which is our age column. 19 00:01:24,430 --> 00:01:31,990 So we want over 50 because remember we're working with our over 50 data frame now age and then our y 20 00:01:32,020 --> 00:01:42,040 column is going to be over 50 and we're going to have Shiloh call for cholesterol and then we want to 21 00:01:42,040 --> 00:01:47,650 color it with over 50 which is the C.. 22 00:01:47,650 --> 00:01:51,010 Here we want to color it with the target column. 23 00:01:51,080 --> 00:01:57,340 What I mean by color it is just literally change the color of a dot depending on what the target column 24 00:01:57,340 --> 00:02:01,990 value is and now let's see what this looks like. 25 00:02:02,040 --> 00:02:05,690 Okay groovy we're starting to get a few different colors here. 26 00:02:05,730 --> 00:02:11,250 It's looking similar but it's still missing a few things like We don't know what the x axis is and we 27 00:02:11,250 --> 00:02:12,970 don't know what the y axis is. 28 00:02:13,110 --> 00:02:13,920 But that's okay. 29 00:02:13,940 --> 00:02:19,140 We've got a very flexible method here because we're using the object orientated method from scratch. 30 00:02:19,560 --> 00:02:25,090 So now what we're going to do is customize and we're going to go ax dot set. 31 00:02:25,090 --> 00:02:27,390 We want to add in a title beautiful. 32 00:02:27,670 --> 00:02:33,610 So we got heart disease and cholesterol levels. 33 00:02:33,610 --> 00:02:34,440 That's right. 34 00:02:34,480 --> 00:02:36,120 Keep it nice and concise. 35 00:02:36,180 --> 00:02:46,760 Now we want X label equals age and we'll go we'll add a y label which is cholesterol now you could put 36 00:02:46,760 --> 00:02:47,420 the units here. 37 00:02:47,420 --> 00:02:51,780 I'm not actually sure what the units are of cholesterol that would be something we'd have to look up. 38 00:02:51,830 --> 00:02:55,760 So we'll just keep that is just cholesterol nice and simple for the time being. 39 00:02:55,910 --> 00:02:56,950 Let's see what this looks like. 40 00:02:59,200 --> 00:03:00,280 Starting to get better. 41 00:03:00,640 --> 00:03:01,150 All right. 42 00:03:01,720 --> 00:03:07,330 So we've got a title now we know what the y axis is and we know what the x axis is but we're not sure 43 00:03:07,330 --> 00:03:09,020 what these dots are. 44 00:03:09,100 --> 00:03:09,360 Right. 45 00:03:09,370 --> 00:03:13,480 These are just purple and yellow dots so what color is that to you. 46 00:03:13,660 --> 00:03:18,610 It's a purplish to me so maybe we. 47 00:03:19,440 --> 00:03:21,630 See that's what happens when you run it without the semicolon. 48 00:03:21,640 --> 00:03:25,500 You get this code output so maybe we add a legend. 49 00:03:25,930 --> 00:03:32,560 So how can we do that we got ax we call that the legend method legend and then we're going to use this 50 00:03:32,560 --> 00:03:37,450 little star which is kind of like just unpack all the values 51 00:03:40,770 --> 00:03:48,870 of Tide or vehicles target let's add a legend to our axis which is this here and this little star is 52 00:03:48,870 --> 00:03:57,360 saying Hey grab the values from scatter and unpack the legend elements which is going to query this 53 00:03:57,360 --> 00:04:05,060 C parameter here and look back at this data frame and go what values are in this in the target column. 54 00:04:05,070 --> 00:04:11,850 So we've got ones and zeros and then it's going to create the legend built off those elements. 55 00:04:11,910 --> 00:04:18,620 So let's see it in action path collection has no attribute legend elements. 56 00:04:18,650 --> 00:04:19,930 Mm hmm. 57 00:04:20,480 --> 00:04:21,530 Oh there we go. 58 00:04:21,700 --> 00:04:25,130 Typedef beautiful. 59 00:04:25,190 --> 00:04:26,390 So if you type it right. 60 00:04:26,390 --> 00:04:27,830 That's what it's going to do. 61 00:04:27,830 --> 00:04:33,890 It just goes into the scatter variable which is what we've created up here and then it's gonna find 62 00:04:33,890 --> 00:04:41,210 a legend elements which it gets from this C parameter which it then looks back up into our we'll put 63 00:04:41,210 --> 00:04:52,220 it here so we can see over 50 target values it's going to look at this target column and then find that 64 00:04:52,280 --> 00:04:58,440 this ones and zeros and then it's going to color the legend the same as the values on here. 65 00:04:58,700 --> 00:05:00,420 So now this is looking a bit better. 66 00:05:00,500 --> 00:05:05,960 The object orientated method from scratch is looking far better than what we've built here. 67 00:05:05,990 --> 00:05:12,260 This is how we've done a few more lines of code here but now you're starting to see how customizable 68 00:05:12,320 --> 00:05:15,010 this object orientated API is. 69 00:05:15,050 --> 00:05:17,090 What if we wanted to add a few more things. 70 00:05:17,090 --> 00:05:19,790 Well the beautiful thing is we can do that. 71 00:05:19,850 --> 00:05:26,510 What if we wanted something like a a horizontal line across here to indicate the average cholesterol. 72 00:05:26,510 --> 00:05:38,170 Let's look at the documentation how to add a horizontal line and map plot lib plot map what lived on 73 00:05:38,170 --> 00:05:40,700 axis that X Hage line. 74 00:05:40,780 --> 00:05:48,380 Okay what will this do add a horizontal line across the axis. 75 00:05:49,180 --> 00:05:51,610 Well I guess that's what we want to do. 76 00:05:51,760 --> 00:05:53,400 So let's try it out. 77 00:05:53,410 --> 00:05:58,840 We want to get a medevac up in here add a horizontal line. 78 00:05:58,840 --> 00:06:03,190 So this is the kind of workflow you'll go through like if you wanted to do something that's perfectly 79 00:06:03,190 --> 00:06:09,800 fine you look it up you go to the documentation and now we're going to try this out axes dot ax Hage 80 00:06:09,800 --> 00:06:10,990 line. 81 00:06:11,090 --> 00:06:16,800 Let's see what happens X because this is our axes dot ax Hage line. 82 00:06:16,850 --> 00:06:17,930 Wonderful. 83 00:06:17,970 --> 00:06:20,310 And now we want to give it the value. 84 00:06:20,330 --> 00:06:21,880 So we want over 50. 85 00:06:21,970 --> 00:06:25,950 So if we go shift tab and see what it takes why. 86 00:06:26,030 --> 00:06:27,200 So we need a Y axis. 87 00:06:27,200 --> 00:06:29,930 So we want to give it the same y here. 88 00:06:29,930 --> 00:06:34,320 So what the cholesterol column yeah beautiful. 89 00:06:34,320 --> 00:06:40,000 And now we want the line to be the main of that column beautiful. 90 00:06:40,060 --> 00:06:45,770 Now we've got a straight line but maybe we wanted a dash line because that looks a bit better. 91 00:06:45,880 --> 00:06:47,590 We've got line style. 92 00:06:47,590 --> 00:06:52,530 So this is this is another one of those keyword arguments so this one here keyword args. 93 00:06:53,020 --> 00:06:58,020 That's not really going to appear in the docs string. 94 00:06:58,020 --> 00:07:04,950 Maybe if we scrolled right down there would go line style so you could also just look up how to style 95 00:07:05,190 --> 00:07:10,070 map plot line line style reference. 96 00:07:10,110 --> 00:07:14,390 You come across something like this but in our case we save a little time. 97 00:07:14,540 --> 00:07:18,370 I've used this dash line before and that that usually looks pretty good. 98 00:07:18,380 --> 00:07:19,160 So there we go. 99 00:07:19,160 --> 00:07:25,600 We've added a horizontal line now that's starting to look much much better than what we had before. 100 00:07:25,610 --> 00:07:27,080 Don't you agree. 101 00:07:27,080 --> 00:07:31,490 Well I certainly do but I'm kind of biased because I I created this plot. 102 00:07:31,490 --> 00:07:36,950 Now this is just another example right of using a different dataset of creating your own custom plot 103 00:07:37,370 --> 00:07:39,950 and then working with different kinds of data. 104 00:07:39,950 --> 00:07:45,320 So you've got cholesterol and then really starting to use the map plot layer API to create whatever 105 00:07:45,320 --> 00:07:49,400 kind of plot you want now you could imagine you could create a subplot of this. 106 00:07:49,560 --> 00:07:55,310 We might actually do that in the next video is create this but we'll work it in with a subplot so we 107 00:07:55,310 --> 00:08:00,890 might add another variable from the data frame and put it into a subplot of this. 108 00:08:00,950 --> 00:08:02,060 So let's see that in action. 109 00:08:02,210 --> 00:08:07,040 But in the meantime have a little bit of a play around maybe you can take a step ahead and see if you 110 00:08:07,040 --> 00:08:13,430 can create a subplot of heart disease and cholesterol levels with maybe heart disease and and what's 111 00:08:13,430 --> 00:08:15,340 another column that you could use. 112 00:08:15,530 --> 00:08:18,980 And this one fail act which is max heart rate. 113 00:08:19,010 --> 00:08:23,960 See what you can do creating a subplot with cholesterol and max heart rate. 114 00:08:23,960 --> 00:08:26,750 If you want me to go along with you we'll do that next video.