1 00:00:00,580 --> 00:00:01,640 Welcome back. 2 00:00:01,690 --> 00:00:05,990 In the last video we checked out a few different methods of creating that plot. 3 00:00:05,990 --> 00:00:08,570 Live plots and figures. 4 00:00:08,620 --> 00:00:12,070 That name is kind of interchangeable same with the name visualization. 5 00:00:12,070 --> 00:00:17,470 If you hear that they're often referring to the same thing and we looked at a little trick with the 6 00:00:17,650 --> 00:00:23,340 little percentage sign to set up map plot lib so that our plots appear in our Jupiter notebooks. 7 00:00:23,350 --> 00:00:29,680 So now we're going to start this video off by checking out the map plot lib and anatomy of a figure 8 00:00:30,880 --> 00:00:31,850 so let's have a look. 9 00:00:31,880 --> 00:00:38,290 As I just said I got anatomy of a map plot lib plot and I just said we're going to check out the anatomy 10 00:00:38,290 --> 00:00:39,050 of a figure. 11 00:00:39,080 --> 00:00:41,850 So this is how I mean these words are very interchangeable. 12 00:00:41,850 --> 00:00:46,110 So I want you to be aware of that whenever you're looking at that plot live online. 13 00:00:46,150 --> 00:00:51,280 If you go in a stack overflow or whatever resource that documentation probably is more formal using 14 00:00:51,280 --> 00:00:53,490 the word figure we'll see that in a moment. 15 00:00:53,530 --> 00:01:00,250 But it refers to plot or visualization there always meaning kind of the same thing which is this complicated 16 00:01:00,280 --> 00:01:01,570 but beautiful mess here. 17 00:01:02,410 --> 00:01:08,540 So if we look at it figure is kind of like the giant section here the everything. 18 00:01:08,540 --> 00:01:13,640 The blue square sort of figure contains all of it it's like the blank canvas and then what we're going 19 00:01:13,640 --> 00:01:18,280 to do is start to add things as we go to make our plots look beautiful. 20 00:01:18,590 --> 00:01:20,250 So we've got some data here. 21 00:01:20,270 --> 00:01:22,460 This is heart disease analysis. 22 00:01:22,460 --> 00:01:24,040 This is the center title. 23 00:01:24,110 --> 00:01:27,540 Don't worry if this looks a little bit more complicated than the plot we've just done. 24 00:01:27,620 --> 00:01:29,500 This is a very simple plot here. 25 00:01:29,510 --> 00:01:34,430 This one's got a bit of fancy colors and a horizontal line titles and legends. 26 00:01:34,460 --> 00:01:38,420 We're going to work towards making something like this but by the end of the section so we'll get there 27 00:01:38,420 --> 00:01:39,160 in a moment. 28 00:01:39,320 --> 00:01:42,650 But you can see here these two axes. 29 00:01:42,650 --> 00:01:43,880 This is a subplot. 30 00:01:43,910 --> 00:01:46,640 We've got one plot here actually zero. 31 00:01:46,970 --> 00:01:48,590 And this is axes one. 32 00:01:48,620 --> 00:01:50,710 So there's two types of information here. 33 00:01:50,840 --> 00:01:54,670 But they share an x axis which is the age. 34 00:01:54,740 --> 00:01:56,860 We've got an x axis label here. 35 00:01:57,020 --> 00:01:58,810 We've got axes one tidal wave. 36 00:01:58,820 --> 00:02:00,210 This one's got a legend. 37 00:02:00,230 --> 00:02:01,550 So does this. 38 00:02:01,550 --> 00:02:04,160 And then we've got two different y axes label. 39 00:02:04,160 --> 00:02:07,940 So this one is max heart rate and this one is cholesterol. 40 00:02:08,240 --> 00:02:10,780 And we've got a main line going through here. 41 00:02:10,880 --> 00:02:14,470 You might want to take a screenshot of this but don't worry it'll be in the resources section. 42 00:02:14,480 --> 00:02:19,910 This is kind of the anatomy of most map plot live plots that you'll check out at least for 2D plots 43 00:02:19,910 --> 00:02:20,690 anyway. 44 00:02:20,780 --> 00:02:27,410 So yeah you've got label titles and what all these little things do is that they just add to the communication 45 00:02:27,410 --> 00:02:27,800 value. 46 00:02:27,830 --> 00:02:33,740 Of course you could make a plot without these titles or these horizontal lines or these fancy colors 47 00:02:34,100 --> 00:02:36,380 but it would be kind of hard to understand. 48 00:02:36,380 --> 00:02:38,290 So that's why we add these things here. 49 00:02:38,750 --> 00:02:42,500 Let's go back before we jump into the next video. 50 00:02:43,350 --> 00:02:46,430 Let's have a little bit of a look where the object oriented comes from. 51 00:02:46,440 --> 00:02:53,660 So if we go back to this cell here we might go type thing type 52 00:02:56,840 --> 00:02:57,860 so here we go. 53 00:02:57,860 --> 00:02:59,960 We've got map plot libbed figure dot figure. 54 00:03:00,110 --> 00:03:05,930 So the formal definition for something like this is a figure and then we have map plot lib dot axes 55 00:03:05,930 --> 00:03:08,300 dot subplots to access subplot. 56 00:03:08,300 --> 00:03:13,470 So this is what it means when that plot labor talks about the object oriented API. 57 00:03:13,880 --> 00:03:18,230 So we've got the figure object which is back to our anatomy. 58 00:03:18,230 --> 00:03:19,800 This is the figure object here. 59 00:03:19,850 --> 00:03:25,330 This big blue square and then we have the axes objects and now the axes objects. 60 00:03:25,330 --> 00:03:32,300 They're always kind of a subplot because this is a subplot on a figure but you can have more than one 61 00:03:32,360 --> 00:03:34,670 axes on a figure if that makes sense. 62 00:03:34,670 --> 00:03:39,440 If we had two more of these over here this blue box would stretch out to cover those. 63 00:03:39,440 --> 00:03:46,230 So the figure is the base canvas and the axes are like we're drawing on that base canvas now that we've 64 00:03:46,230 --> 00:03:50,850 kind of understood the fundamentals of map plot layer with the figure and the accesses. 65 00:03:50,910 --> 00:03:54,490 Let's check out a workflow in its entirety. 66 00:03:54,600 --> 00:04:00,070 So we'll type in here map plot lib example workflow. 67 00:04:00,120 --> 00:04:04,470 Make this a heading so it's a little bit separate map plot lib example workflow. 68 00:04:04,590 --> 00:04:16,090 So step 0 is import map plot lib and get it ready for plotting in Jupiter beautiful. 69 00:04:16,090 --> 00:04:20,470 Now we've already done this but I would just want to do it all in one cell so you can see it happening 70 00:04:20,690 --> 00:04:32,040 that partly inline import map plot lib dot higher plot as P L T step one is to prepare some data prepare 71 00:04:32,050 --> 00:04:38,980 data X equals we'll keep it nice and simple just as we did before but you'll see in reality X and Y 72 00:04:38,980 --> 00:04:47,970 can be basically any data or any numbers that you can imagine will go to number three we're getting 73 00:04:47,970 --> 00:04:49,110 ahead of ourselves here. 74 00:04:49,200 --> 00:04:50,380 Set up plot. 75 00:04:50,490 --> 00:04:53,650 Now this is where we use the object orientated method. 76 00:04:53,760 --> 00:04:58,260 Fig ax equals P LTV dot subplots. 77 00:04:58,260 --> 00:05:02,220 We're gonna throw in a little keyword here that I want to introduce you because you'll see this a lot. 78 00:05:02,220 --> 00:05:05,280 Fig size 10 10. 79 00:05:05,280 --> 00:05:07,260 Now let's see what this means. 80 00:05:07,380 --> 00:05:08,550 Can we go shift tab. 81 00:05:08,550 --> 00:05:09,440 Yes we can. 82 00:05:10,080 --> 00:05:10,880 We go down. 83 00:05:10,890 --> 00:05:11,870 Is it going to have it. 84 00:05:12,040 --> 00:05:15,620 It might not figure size parameters. 85 00:05:17,060 --> 00:05:18,290 We'll keep scrolling through here. 86 00:05:18,290 --> 00:05:22,180 It's a bit hard to see excise acts. 87 00:05:22,200 --> 00:05:23,400 Examples. 88 00:05:23,400 --> 00:05:24,950 Well I'll just tell you what it is. 89 00:05:25,180 --> 00:05:30,930 Oh you can practice looking at the documentation but what this essentially means is it just height and 90 00:05:30,930 --> 00:05:33,060 width and they may be back to front. 91 00:05:33,060 --> 00:05:34,460 It's usually x then y. 92 00:05:34,470 --> 00:05:36,900 So this is probably width and this is probably height. 93 00:05:36,990 --> 00:05:40,840 That just means the dimensions of this plot so we'll get here. 94 00:05:41,790 --> 00:05:46,020 Then we'll go to number three which is plot the data. 95 00:05:46,090 --> 00:05:51,270 So we want to add to our x x and y. 96 00:05:51,490 --> 00:05:52,230 What have we done here. 97 00:05:52,230 --> 00:05:57,460 We've created the figure and we've created an axes and now what we're doing is adding data to our axes. 98 00:05:58,050 --> 00:05:58,390 Okay. 99 00:05:58,510 --> 00:05:58,770 Yeah. 100 00:05:58,780 --> 00:06:02,740 This is making sense for and then we want to customize plots. 101 00:06:02,740 --> 00:06:08,910 Now we haven't seen names but they're fairly intuitive so I'll let you guess as I'm typing them out 102 00:06:08,920 --> 00:06:09,940 simple plot. 103 00:06:09,940 --> 00:06:13,180 That's a good title I think what they actually mean. 104 00:06:13,180 --> 00:06:18,100 So now that we've we've done just one what do you think we've got we've got X dots set and then a parameter 105 00:06:18,100 --> 00:06:22,530 saying Title X equals simple plot x axis. 106 00:06:22,540 --> 00:06:29,020 We'll keep the titles for the X and Y nice and simple Y equals Y axes. 107 00:06:29,080 --> 00:06:30,170 Wonderful. 108 00:06:30,430 --> 00:06:32,870 And then we'll go to number five. 109 00:06:32,950 --> 00:06:38,370 You probably wouldn't usually do this I'm just showing you all this in one hit just for the sake of 110 00:06:38,370 --> 00:06:45,210 seeing a map plotted workflow running live save the whole figure. 111 00:06:45,270 --> 00:06:46,400 That's what I'm looking for. 112 00:06:46,620 --> 00:06:48,830 That's what I said out loud but that's what I didn't type. 113 00:06:48,860 --> 00:06:49,600 Fig. 114 00:06:49,830 --> 00:06:51,510 Don't save Fig. 115 00:06:51,750 --> 00:06:54,030 And then we want to save it too. 116 00:06:54,030 --> 00:06:58,770 I've got the images folder set up that I already have prepared earlier so you can save it wherever you 117 00:06:58,770 --> 00:07:03,010 want but this is just going to be the path name sample plot PNG. 118 00:07:03,030 --> 00:07:03,580 There we go. 119 00:07:03,600 --> 00:07:04,530 So let's step through this. 120 00:07:04,530 --> 00:07:05,700 We import map pot lib. 121 00:07:05,700 --> 00:07:13,050 We tell Jupiter that we want to plot our map plot lib plots in line or figures in line so within the 122 00:07:13,050 --> 00:07:15,220 notebook we've created some data. 123 00:07:15,270 --> 00:07:16,190 X and Y. 124 00:07:16,350 --> 00:07:17,490 We've set up a plot. 125 00:07:17,660 --> 00:07:21,630 Okay a figure we've given it a size of 10 by 10. 126 00:07:21,690 --> 00:07:27,090 We've added some data to the plot on our axis and then we've customized the plot. 127 00:07:27,090 --> 00:07:32,030 Now can you guess what's going to happen here if we look at this. 128 00:07:32,170 --> 00:07:38,480 Then if we compare it to our anatomy we've got a title we've got X and Y labels. 129 00:07:39,240 --> 00:07:41,530 Can you guess what this is going to do here. 130 00:07:42,300 --> 00:07:47,160 We'll see in the second member if in doubt run the code and then we're going to save a figure here. 131 00:07:47,400 --> 00:07:49,290 We could share it out like that. 132 00:07:49,290 --> 00:07:51,820 Let's see what this does. 133 00:07:51,870 --> 00:07:53,080 We got an error. 134 00:07:53,400 --> 00:07:53,950 That's all right. 135 00:07:54,030 --> 00:07:56,390 No such directory. 136 00:07:56,460 --> 00:07:56,970 That's right. 137 00:07:56,970 --> 00:08:00,570 I thought I knew the path of my image directory doesn't really matter. 138 00:08:00,570 --> 00:08:01,380 Images. 139 00:08:01,470 --> 00:08:02,580 What have I got wrong. 140 00:08:02,730 --> 00:08:03,420 Images. 141 00:08:03,630 --> 00:08:06,650 I don't think I need the dot dot. 142 00:08:06,660 --> 00:08:07,380 There we go. 143 00:08:07,380 --> 00:08:08,790 Simple plot. 144 00:08:08,790 --> 00:08:10,330 So this is a 10 by 10 figure. 145 00:08:10,440 --> 00:08:19,210 So let's practice this maybe we change this to 5 Okay yeah so that was width so this is width quite 146 00:08:20,650 --> 00:08:22,150 beautiful. 147 00:08:22,150 --> 00:08:25,310 Oh yeah well that's not looking very good so let's put that back to 10. 148 00:08:25,330 --> 00:08:26,020 Wonderful. 149 00:08:26,020 --> 00:08:31,870 And so now we can see the title is simple plot the Y label is y axis and the X label is x axis. 150 00:08:31,900 --> 00:08:38,980 Of course if you had some data on here that was more specific you might want to label your x and y axis 151 00:08:38,980 --> 00:08:41,330 is tailored to your data. 152 00:08:41,410 --> 00:08:44,140 But in our case this is just a nice and simple plot. 153 00:08:44,140 --> 00:08:48,670 As we've got the title here and if we go back up here check in our images folder. 154 00:08:48,670 --> 00:08:56,380 We've got sample plot dot Peng G which if you didn't want to write this line of code you can also right 155 00:08:56,380 --> 00:09:01,990 click and go save image as but that is enough you've seen a map hotly workflow. 156 00:09:02,020 --> 00:09:06,390 You've also seen the anatomy of a map plot leave a plot or figure. 157 00:09:06,910 --> 00:09:10,870 So before the next video try to create your own plot like this. 158 00:09:10,900 --> 00:09:13,480 Get his fancy as you like create a little bit of data. 159 00:09:13,510 --> 00:09:16,750 You could try create an umpire and plot him see how you go. 160 00:09:17,260 --> 00:09:18,610 Otherwise I'll see you soon.