1 00:00:00,180 --> 00:00:01,640 Welcome back. 2 00:00:01,650 --> 00:00:03,710 Now we're really going to step it up a notch. 3 00:00:03,720 --> 00:00:09,150 We're going to see the full power of the map politely but object orientated method. 4 00:00:09,180 --> 00:00:11,290 We're going to build upon what we've done here. 5 00:00:11,370 --> 00:00:16,820 So we've created this this heart disease and cholesterol levels with our over 50s data frame. 6 00:00:16,950 --> 00:00:23,820 But now we're going to add a subplot to this so we can visualize cholesterol levels and we might get 7 00:00:23,820 --> 00:00:30,370 out over 50 data frame here so we can stop having to scroll up we're going to combine that with fell 8 00:00:30,370 --> 00:00:37,030 act which is I'm not sure if I'm pronouncing that by the way either fell ash which is Mack's heart rate. 9 00:00:37,060 --> 00:00:43,540 So we want to have a subplot where we've got cholesterol and fell patch on the y axis is but they're 10 00:00:43,540 --> 00:00:46,850 both going to have age as the x axis. 11 00:00:46,870 --> 00:00:48,520 So let's see that in action. 12 00:00:48,820 --> 00:01:00,730 We want to title this subplot of coal age though which beautiful Well we want to go here. 13 00:01:00,750 --> 00:01:05,370 We're going to recreate this we could copy and paste this code but again we want to practice writing 14 00:01:05,370 --> 00:01:05,970 from scratch. 15 00:01:05,980 --> 00:01:08,220 So let's see it in full force Fig. 16 00:01:08,790 --> 00:01:10,860 We want to use the object orientated method. 17 00:01:10,860 --> 00:01:14,490 Now if you've had a go at creating a subplot on your own. 18 00:01:14,700 --> 00:01:19,890 This is the way you might have used but if not this is how I would create a subplot of these two. 19 00:01:19,890 --> 00:01:22,780 So remember we want two different accesses. 20 00:01:22,860 --> 00:01:26,120 So fig axe zero and ax. 21 00:01:26,160 --> 00:01:27,330 This is gonna be ax one. 22 00:01:27,330 --> 00:01:27,900 There we go. 23 00:01:27,930 --> 00:01:35,330 So what this is saying is now we're creating a single figure but it's going to have two axes on it. 24 00:01:35,340 --> 00:01:41,820 Remember axes are this year why in X where you can add data. 25 00:01:41,820 --> 00:01:45,180 So let's use the same commanders before some plots. 26 00:01:45,200 --> 00:01:48,060 And I want to end rows equals two. 27 00:01:48,180 --> 00:01:53,400 We want in calls is gonna be one our previous figure size was 10 and six. 28 00:01:53,400 --> 00:01:57,350 But let's make this ten and ten see what that looks like. 29 00:01:57,450 --> 00:02:01,030 And now we want to go add data to ax zero. 30 00:02:01,080 --> 00:02:06,240 Actually let's see what this looks like before we even plot fig size. 31 00:02:06,240 --> 00:02:10,300 Oh we got an equal there beautiful. 32 00:02:10,330 --> 00:02:14,420 So now we've got two blank canvases to start adding our data on here. 33 00:02:14,420 --> 00:02:21,730 So we want to add data to access zero which is this one here so just gonna be this exact same as before. 34 00:02:21,910 --> 00:02:24,220 We'll do something like this. 35 00:02:24,310 --> 00:02:28,210 So now we're gonna add some data to access zero just like we've done up here. 36 00:02:28,210 --> 00:02:32,910 We're gonna do something similar to this but again we're not copying pasting we'll do it from scratch 37 00:02:32,920 --> 00:02:43,690 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 38 00:02:44,930 --> 00:02:47,600 Y equals over 50. 39 00:02:47,630 --> 00:02:51,190 And this is gonna be just a collateral column beautiful. 40 00:02:51,350 --> 00:02:58,690 And then we're going to go see equals we're gonna color it with over 50 target column. 41 00:02:58,730 --> 00:02:59,840 Now let's see what that looks like. 42 00:03:01,520 --> 00:03:03,080 Beautiful we've seen this before. 43 00:03:03,080 --> 00:03:11,630 So customize at 0 0 we want to go X 0 dot set and we want to add a title. 44 00:03:11,840 --> 00:03:18,200 This is gonna be heart disease and cholesterol levels. 45 00:03:18,200 --> 00:03:19,190 Wonderful. 46 00:03:19,250 --> 00:03:30,000 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. 47 00:03:30,410 --> 00:03:36,420 Nothing new here we've seen this before but now it's only on axis zero which is amazing. 48 00:03:36,440 --> 00:03:48,020 Maybe we add at a legend to act zero same code as a four x zero dot legend scatter dot legend elements 49 00:03:49,130 --> 00:03:50,230 and then we're going to go. 50 00:03:50,230 --> 00:03:52,760 Title Eagle's target. 51 00:03:52,940 --> 00:03:53,900 Beautiful. 52 00:03:53,900 --> 00:03:55,400 What did we have up here. 53 00:03:55,430 --> 00:03:56,330 We had a main line. 54 00:03:56,360 --> 00:03:57,860 So that's what we can do with the hate line. 55 00:03:57,950 --> 00:03:59,730 So add a main line. 56 00:03:59,810 --> 00:04:04,600 So we're just replicating the plot we've done before axis zero dot. 57 00:04:04,730 --> 00:04:09,960 Page line No we need to pass hate line of why so we want over 50s. 58 00:04:11,120 --> 00:04:13,610 It's going to be a cholesterol. 59 00:04:13,670 --> 00:04:28,770 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 60 00:04:28,770 --> 00:04:30,420 as what we've got above. 61 00:04:30,420 --> 00:04:38,420 But now it's on a subplot so I want to challenge you to before we go through it. 62 00:04:38,650 --> 00:04:47,200 See if you can replicate what we've done here but with the foul ash column instead of the cholesterol 63 00:04:47,200 --> 00:04:52,220 column on this subplot here I'll give you a second. 64 00:04:54,120 --> 00:04:54,420 All right. 65 00:04:54,630 --> 00:04:55,340 If you had a go. 66 00:04:55,590 --> 00:04:56,250 All good. 67 00:04:56,250 --> 00:04:57,760 If not let's go through it. 68 00:04:57,990 --> 00:05:04,530 So now we want to add data to ax 1 because remember we've got X one up here. 69 00:05:04,530 --> 00:05:05,870 Excellent. 70 00:05:05,890 --> 00:05:11,870 Same thing we've done before but this time all we're going to do is change it from ax zero to ax 1. 71 00:05:11,970 --> 00:05:17,010 And then of course the column will be different all the data that we use will be a little bit different. 72 00:05:17,700 --> 00:05:22,770 So in this case it's 1 x the X is still going to be the age column. 73 00:05:22,770 --> 00:05:24,990 What's going to change is what's on the y axis. 74 00:05:25,020 --> 00:05:29,830 So we are over 50 now actually. 75 00:05:29,880 --> 00:05:30,690 Wonderful. 76 00:05:30,790 --> 00:05:35,880 Color is gonna be the same because we're focused on our target variable which is whether or not the 77 00:05:35,910 --> 00:05:37,200 patient has heart disease. 78 00:05:37,680 --> 00:05:38,790 So there we go. 79 00:05:39,000 --> 00:05:41,690 Let's see what this looks like okay. 80 00:05:41,760 --> 00:05:43,240 So we're starting to get somewhere now. 81 00:05:43,280 --> 00:05:49,080 We've got some data on both our axis is let's customize it just like we've done with Axis zero. 82 00:05:49,530 --> 00:05:55,430 And do that with x 1 x 1 don't set let's add a title title. 83 00:05:55,440 --> 00:06:01,190 This one will be heart disease and max heart right. 84 00:06:03,150 --> 00:06:03,910 Wonderful. 85 00:06:04,500 --> 00:06:06,470 And then we're going to go X label. 86 00:06:06,920 --> 00:06:12,780 Okay everyone that is just that age because we're using the same column for The X and the Y label. 87 00:06:12,980 --> 00:06:17,370 This is gonna be fell act so we'll actually put in max heart rate because we want it to be a bit more 88 00:06:17,370 --> 00:06:19,850 communicative than just that latch. 89 00:06:19,860 --> 00:06:25,230 So if someone came and had a look at our plot didn't know what flash meant they'll know it means max 90 00:06:25,230 --> 00:06:28,110 heart rate okay. 91 00:06:28,320 --> 00:06:30,270 Standing graphics and progress. 92 00:06:30,270 --> 00:06:31,710 Now we still have a couple more things to do. 93 00:06:31,710 --> 00:06:34,190 We want a similar set up to what we've got here. 94 00:06:35,600 --> 00:06:42,740 So let's add a legend to X1 axe one bolt legend. 95 00:06:42,740 --> 00:06:48,530 Now again we're creating quite similar plots here with the subplot that we're making. 96 00:06:48,530 --> 00:06:54,110 So these two are quite similar as you've seen before you could have a scatter plot here and you could 97 00:06:54,110 --> 00:06:58,980 have a histogram here or something like that but we're just using this as an example. 98 00:06:59,030 --> 00:07:02,680 So title ego's target wonderful. 99 00:07:02,690 --> 00:07:04,450 Well I don't mean line as well. 100 00:07:04,850 --> 00:07:07,280 So Ax one dot ax. 101 00:07:07,460 --> 00:07:13,010 Page line now we're gonna color it with the Y is going to be this time instead of cholesterol it's going 102 00:07:13,010 --> 00:07:21,920 to be all that wonderful dot main and then the line style we're going to keep it with our trusty dash 103 00:07:22,400 --> 00:07:27,400 and then we'll add a semicolon here and let's have a look. 104 00:07:27,590 --> 00:07:28,740 What have we messed up. 105 00:07:28,760 --> 00:07:31,850 We got an error line today has no property line star. 106 00:07:31,850 --> 00:07:34,630 This is classic typos everywhere. 107 00:07:34,640 --> 00:07:35,570 Here we go. 108 00:07:35,570 --> 00:07:36,850 So it's okay to make errors right. 109 00:07:36,860 --> 00:07:42,890 You're never going to type out all the code correctly every time the first time beautiful. 110 00:07:42,960 --> 00:07:45,200 This is starting to look really good. 111 00:07:45,200 --> 00:07:46,320 Okay. 112 00:07:46,460 --> 00:07:53,510 What we're starting to see we've got to age x axis label here but this is also age so maybe we could 113 00:07:53,570 --> 00:07:56,700 tell them to share the X.. 114 00:07:56,810 --> 00:08:00,850 So let's say where can we add that maybe have in here. 115 00:08:00,930 --> 00:08:04,610 I want to share the X so share X equals true 116 00:08:07,700 --> 00:08:16,260 but now we can remove this label on access zero so what is this going to do if we put in share X equals 117 00:08:16,260 --> 00:08:17,830 true. 118 00:08:17,910 --> 00:08:21,570 What do you think. 119 00:08:21,670 --> 00:08:22,990 There we go. 120 00:08:22,990 --> 00:08:30,790 So what this is done is it's telling our plot to go that our subplots here have the same x value so 121 00:08:30,820 --> 00:08:34,880 we don't need to put in the age label there maybe you would keep it in there for a bit more. 122 00:08:34,920 --> 00:08:39,910 So it's a bit more communicative that's kind of one way you can start to clean up your plots. 123 00:08:40,060 --> 00:08:45,260 And now what we might do is add a title to this overall things. 124 00:08:45,250 --> 00:08:50,580 We've got both subplots are titled What we might want to title the entire figure. 125 00:08:50,710 --> 00:08:52,210 So let's see how we do that. 126 00:08:52,450 --> 00:08:54,940 Add a title to the figure. 127 00:08:55,020 --> 00:09:00,850 Now this is big because remember we've created a figure and we've added data and customization for the 128 00:09:00,850 --> 00:09:07,150 actresses but now we want to start to access the figure directly which is that big blue square on our 129 00:09:07,750 --> 00:09:09,020 map plot level anatomy. 130 00:09:09,070 --> 00:09:10,960 We filled up these two and our subplots. 131 00:09:10,960 --> 00:09:17,680 Now we want a title our figure so we can do that with Fig Doc sup which he stands for I think it says 132 00:09:17,680 --> 00:09:20,710 for Super title I actually don't know what some stand for. 133 00:09:20,710 --> 00:09:23,450 I just know that it's subtitle and then we go. 134 00:09:23,440 --> 00:09:31,820 Heart disease analysis and we'll create the font size we want it to be pretty big font size and a font 135 00:09:32,510 --> 00:09:39,380 weight of bold and put a semicolon at the end beautiful. 136 00:09:39,380 --> 00:09:40,010 Look at this. 137 00:09:40,010 --> 00:09:45,410 Maybe we have to zoom out a tiny bit so we can see it all in one hit. 138 00:09:45,560 --> 00:09:46,350 There we go. 139 00:09:46,360 --> 00:09:49,510 Are you starting to see what this is kind of looking like. 140 00:09:49,580 --> 00:09:54,090 Remember right at the start in the concept lecture we looked at the anatomy of a map plotted figure. 141 00:09:54,110 --> 00:09:58,340 We looked at that plant and it was quite complex has a lot going on. 142 00:09:58,380 --> 00:10:06,150 Well what you've done is you've just followed along and recreated something very similar. 143 00:10:06,450 --> 00:10:12,030 Now what we're going to do in the next video is style this a little bit better so fix up some of the 144 00:10:12,030 --> 00:10:12,970 colors. 145 00:10:13,020 --> 00:10:17,640 The important thing to remember is it looks like a lot of code here and actually is. 146 00:10:17,760 --> 00:10:21,300 We've got 25 30 lines of code there. 147 00:10:21,700 --> 00:10:27,730 But what we've done is we've built this figure from scratch using the object orientated map plot lib 148 00:10:27,730 --> 00:10:28,430 method. 149 00:10:28,690 --> 00:10:37,790 And so now what seemed at the start to be a very complex and complicated plot is actually just quite 150 00:10:37,790 --> 00:10:38,450 simple right. 151 00:10:38,450 --> 00:10:45,410 You create a figure you create a couple of accesses you add data to the accesses you add some customizations 152 00:10:45,410 --> 00:10:50,270 like titles and a legend in a horizontal line and you start to get something looking like this. 153 00:10:50,270 --> 00:10:55,790 Now that's something that you can put in a demonstration or show your colleagues in a presentation something 154 00:10:55,790 --> 00:11:02,330 like that right now you're starting to see just how powerful that plot lib object orientated API can 155 00:11:02,330 --> 00:11:02,630 be. 156 00:11:03,990 --> 00:11:09,990 All right let's wrap this video up have a practice maybe create your own subplot without a scatter try 157 00:11:10,110 --> 00:11:11,910 a histogram and maybe a bar graph. 158 00:11:11,910 --> 00:11:14,310 Can you do that on the same figure. 159 00:11:14,370 --> 00:11:19,230 Otherwise I'll see you in the next video and we'll learn a little bit more customization of these plots.