1 00:00:00,360 --> 00:00:02,490 So let's get started with map plot lib. 2 00:00:02,490 --> 00:00:06,940 We're going to start on the desktop and do what we always do and hit the terminal. 3 00:00:07,140 --> 00:00:08,140 Beautiful. 4 00:00:08,220 --> 00:00:10,470 I'll zoom in a little bit on here. 5 00:00:10,470 --> 00:00:10,980 Excellent. 6 00:00:10,980 --> 00:00:13,370 Now we're going to go through a little workflow like we always do. 7 00:00:13,370 --> 00:00:19,540 So we're going to see these for me and get into the sample project folder which contains our environment. 8 00:00:19,620 --> 00:00:25,750 We can always see our environment by using Condit and list so this will show me my environments. 9 00:00:25,750 --> 00:00:27,150 This is the one I'm after here. 10 00:00:27,160 --> 00:00:32,830 Sample project the folder we've been working through before going to seed a I'm on the desktop right 11 00:00:32,830 --> 00:00:33,310 now. 12 00:00:33,360 --> 00:00:34,880 We can see that there. 13 00:00:34,900 --> 00:00:41,470 So go into email course we can see that little folder up here but we're gonna use a command line and 14 00:00:41,470 --> 00:00:44,240 then see it again into sample project. 15 00:00:44,350 --> 00:00:45,310 Beautiful. 16 00:00:45,430 --> 00:00:47,320 And then we can run content activate. 17 00:00:47,320 --> 00:00:51,270 Now you could just copy and paste this and do that there. 18 00:00:51,730 --> 00:00:55,320 But remember we're in the habit of typing out code. 19 00:00:55,600 --> 00:01:01,270 That's a best habit you can develop that way you'll get used to writing things out for yourself and 20 00:01:01,270 --> 00:01:04,810 practicing see what it feels like on your fingers to write code. 21 00:01:04,810 --> 00:01:08,840 So if you conduct activate that should be all correct. 22 00:01:08,860 --> 00:01:09,550 Wonderful. 23 00:01:09,690 --> 00:01:12,850 And so we've had base change from this to this. 24 00:01:12,850 --> 00:01:14,400 We've seen all this before. 25 00:01:14,460 --> 00:01:16,970 I'm going to load up a tube but a notebook. 26 00:01:16,990 --> 00:01:18,460 Our favorite workspace 27 00:01:21,500 --> 00:01:27,930 we've got introduction to num pi pan is we've been through those we're gonna start a new one so now 28 00:01:27,930 --> 00:01:33,480 we're going to retitle this one to be introduction to Matt bot lib. 29 00:01:33,540 --> 00:01:34,860 Beautiful. 30 00:01:34,920 --> 00:01:37,850 Well I have a title introduction to Matt pot lib. 31 00:01:37,850 --> 00:01:41,940 Just so we know what's going on we're in the habit of communicating what we're doing. 32 00:01:42,000 --> 00:01:42,670 There we go. 33 00:01:42,690 --> 00:01:43,760 Beautiful. 34 00:01:43,770 --> 00:01:45,480 And so now we're in a Jupiter notebook. 35 00:01:45,480 --> 00:01:51,420 The first step for always using that plot lib is we might import naptime pandas as well so we import 36 00:01:51,540 --> 00:01:54,000 all the tools we need right at the top of the notebook. 37 00:01:54,000 --> 00:01:55,980 This is kind of a regular workflow. 38 00:01:56,220 --> 00:01:57,510 So when first one order was Matt. 39 00:01:57,510 --> 00:01:59,820 Plot lib in line. 40 00:01:59,830 --> 00:02:01,720 Now if you've never seen this before. 41 00:02:01,860 --> 00:02:06,750 This little percentage sign you might have in a previous video but this is a magic command. 42 00:02:06,750 --> 00:02:13,440 So this percentage sign is telling Jupiter hey we want all of our map plot lib plots our graphs and 43 00:02:13,440 --> 00:02:16,560 visualizations to appear within the notebook. 44 00:02:17,010 --> 00:02:19,550 So that'll make more sense once we run it. 45 00:02:19,590 --> 00:02:23,430 So let's import map plot lib dot pi plot. 46 00:02:23,430 --> 00:02:31,050 Now pi plot is a python plotting module of map plot lib and the convenient name is as penalty will also 47 00:02:31,050 --> 00:02:39,030 get pandas as PD and import num pi as MP and we'll hit shift enter. 48 00:02:39,110 --> 00:02:41,300 This might take a little while depending on what's going on. 49 00:02:41,300 --> 00:02:42,110 Beautiful. 50 00:02:42,110 --> 00:02:45,470 So now we should have all these tools accessible now. 51 00:02:45,500 --> 00:02:52,250 Simplest way to create a plot in map plot lib is with BLT dot plot. 52 00:02:52,250 --> 00:02:55,310 So if we go shift tab I have a look at what this says. 53 00:02:55,310 --> 00:02:59,890 Plot X vs. Y as lines and or markers. 54 00:03:01,040 --> 00:03:05,000 What happens if we just run this huh. 55 00:03:05,230 --> 00:03:11,690 Okay we'll get kind of that empty box that we saw before that was in the map plot lib workflow. 56 00:03:12,160 --> 00:03:13,960 So this is how create a plot. 57 00:03:13,960 --> 00:03:16,360 This is our figure that we've just created. 58 00:03:16,390 --> 00:03:18,310 So we go back to our group a notebook. 59 00:03:18,310 --> 00:03:20,740 This is our figure that we've just created. 60 00:03:20,740 --> 00:03:26,320 But for some reason the output it's giving us these empty brackets so to get rid of those you can put 61 00:03:26,320 --> 00:03:30,410 a semicolon at the end of your plot call. 62 00:03:30,410 --> 00:03:32,780 So let's do that same thing. 63 00:03:32,830 --> 00:03:35,310 We just don't have that nasty little output there. 64 00:03:37,030 --> 00:03:42,580 This is what map plot they have in line means is that this plot is in the notebook so we can see it 65 00:03:42,580 --> 00:03:44,350 visually right here. 66 00:03:44,350 --> 00:03:45,850 That's all that plot Libyan line means. 67 00:03:45,880 --> 00:03:50,060 If we didn't call this it would just output something like this with no plot. 68 00:03:50,140 --> 00:03:56,690 So that's what this line of code is doing does the ideal scenario to always run that when you want to 69 00:03:56,690 --> 00:03:58,570 run map properly it plots. 70 00:03:58,790 --> 00:04:01,150 And now we didn't want to use the semicolon. 71 00:04:01,160 --> 00:04:03,200 We wanted to be a bit more communicated. 72 00:04:03,200 --> 00:04:08,850 We could go plot and then P L T dot show that's gonna do the exact same thing. 73 00:04:08,960 --> 00:04:11,130 We got a nice and blank plot here. 74 00:04:11,140 --> 00:04:16,150 Now how about we add some data so they go BLT dot plot and then hit shift tab. 75 00:04:18,180 --> 00:04:25,770 Plot X vs. Y as lines and or markers and if we click the plus sign gives us a little example here of 76 00:04:25,770 --> 00:04:27,690 plot x y. 77 00:04:27,720 --> 00:04:31,340 So how about we pass it X as a list of some sort. 78 00:04:31,340 --> 00:04:37,770 So maybe we'll just keep it nice and simple one two three four and we'll put the semicolon at the end 79 00:04:38,020 --> 00:04:39,650 and see what happens. 80 00:04:39,680 --> 00:04:40,680 Here we go. 81 00:04:40,680 --> 00:04:43,550 We've got a line so this is on the x axis. 82 00:04:43,560 --> 00:04:46,230 We should have one two three four. 83 00:04:46,380 --> 00:04:47,310 Okay. 84 00:04:47,340 --> 00:04:48,450 Beautiful. 85 00:04:48,480 --> 00:04:50,070 So what can we try next. 86 00:04:50,070 --> 00:04:57,580 Well let's create some x and y data x 1 2 3 four wonderful Y equals. 87 00:04:57,810 --> 00:04:58,830 Let's mix it up a little bit. 88 00:04:58,830 --> 00:05:02,210 11 twenty to thirty three forty four. 89 00:05:02,340 --> 00:05:03,570 Wonderful. 90 00:05:03,570 --> 00:05:10,590 Now let's see what these look like plot on plot x y and we put a semicolon at the end. 91 00:05:10,620 --> 00:05:11,160 There we go. 92 00:05:11,160 --> 00:05:18,720 We notice that our axes have changed so now we've gone from 1 to 4 on the X and from 11 to 44 on the 93 00:05:18,720 --> 00:05:19,300 y. 94 00:05:19,590 --> 00:05:21,680 Okay let's start a make a bit more sense. 95 00:05:21,680 --> 00:05:28,440 This is looking good now this way of plotting and map plot lib is referred to as this stateless way 96 00:05:28,440 --> 00:05:29,280 of plotting. 97 00:05:29,280 --> 00:05:35,100 And if you've ever used Matlab it works like that but if you haven't used Matlab before not to worry 98 00:05:35,430 --> 00:05:43,130 Let's have a quick look at that plot lib documentation because in there it tells us a little bit about 99 00:05:43,700 --> 00:05:55,840 different types of plotting in map plot lib what do you want documentation to tall rails ply plot tutorials 100 00:05:55,860 --> 00:05:59,430 so this is the type of plotting that we're using at the moment not map plot layer. 101 00:05:59,440 --> 00:06:04,090 Pipeline is a collection of command style functions that make map plot layer work like matlab. 102 00:06:04,360 --> 00:06:09,850 So we just went through each pie pop function make some change to a figure creates a figure. 103 00:06:09,850 --> 00:06:11,790 So I've been calling these plots. 104 00:06:11,800 --> 00:06:17,980 They're also referred to as figures creates a plotting area in the figure plot some lines in a plotting 105 00:06:17,980 --> 00:06:23,800 area decorates the plot with labels etc. In my plot lived up high plot various states are preserved 106 00:06:23,800 --> 00:06:24,660 across function calls. 107 00:06:24,670 --> 00:06:25,080 Okay. 108 00:06:25,150 --> 00:06:26,820 Where does reading the documentation here. 109 00:06:27,130 --> 00:06:29,890 So this is the one we're paying attention to. 110 00:06:29,890 --> 00:06:36,430 Note the pipeline API is generally less flexible than the object orientated API. 111 00:06:36,430 --> 00:06:39,840 So remember how I said there's two ways of plotting in that plot lib. 112 00:06:39,880 --> 00:06:45,790 Well we've just looked at the pipeline API and we're going to look at the object orientated API in a 113 00:06:45,790 --> 00:06:52,480 second but this is a while we're gonna be focused on most the object orientated API because we want 114 00:06:52,480 --> 00:06:54,340 as much flexibility as we can get right. 115 00:06:54,860 --> 00:06:56,380 There's one more thing I want to show you. 116 00:06:56,470 --> 00:07:04,250 So if we go map plot lib lifecycle plot the lifecycle of a plot. 117 00:07:04,250 --> 00:07:07,230 There we go and you can get to this in the documentation as well. 118 00:07:07,280 --> 00:07:08,680 So this is just map plot there. 119 00:07:08,690 --> 00:07:13,370 Dot org tutorials lifecycle of a plot. 120 00:07:13,380 --> 00:07:14,300 There we go. 121 00:07:14,370 --> 00:07:21,780 This is the same thing in general trying to use the object orientated interface over the PI plot interface. 122 00:07:21,790 --> 00:07:27,750 Okay so the documentation is saying these two things in bold notes we might listen to it right because 123 00:07:27,750 --> 00:07:31,790 the people who write these documentation I really know what they're doing. 124 00:07:32,130 --> 00:07:43,520 So let's see this is the first method will go fig Eagles now figure short for figure the LTE dot figure. 125 00:07:43,710 --> 00:07:45,690 This creates a figure 126 00:07:48,840 --> 00:07:50,650 axe is short for axes. 127 00:07:50,730 --> 00:07:57,300 So remember this whole thing is a figure but these two lines here are axes so ax equals Fig. 128 00:07:57,430 --> 00:08:00,350 Don't add subplot. 129 00:08:02,720 --> 00:08:10,920 This adds some axes plot don't show where we go so this is just replicated exactly what we did we did 130 00:08:10,920 --> 00:08:19,170 like a kind of a long version of going P ulti felt for same sort of thing here right. 131 00:08:21,300 --> 00:08:25,080 So this is the first method and then you've got the second method 132 00:08:27,860 --> 00:08:32,140 so you want vague equals plot BLT. 133 00:08:32,240 --> 00:08:33,860 And when I say plot I'm referring to. 134 00:08:33,870 --> 00:08:37,990 P L T but because there's no I was just easier for me to say plot. 135 00:08:38,190 --> 00:08:42,910 So creates a figure of being communicated here. 136 00:08:43,010 --> 00:08:49,160 You don't need these comments ax Eagle's fig dot add axes. 137 00:08:49,400 --> 00:08:53,210 And then within here we're gonna add some sample data 1 1 1 1 138 00:08:57,930 --> 00:09:01,550 sorry is going to add axes so these add accesses to the figure. 139 00:09:01,620 --> 00:09:02,530 So there we go. 140 00:09:03,790 --> 00:09:07,480 You've got another figure everyone acts dot plot. 141 00:09:07,510 --> 00:09:13,370 Let's get out x and y on their and then BLT dots show 142 00:09:16,470 --> 00:09:18,260 add some data. 143 00:09:18,260 --> 00:09:18,720 There we go. 144 00:09:18,720 --> 00:09:21,360 We're just creating the same plot. 145 00:09:21,360 --> 00:09:27,090 And now finally we're going to go with the third method and this is the one that we're going to be using. 146 00:09:27,330 --> 00:09:33,210 So we've put in here recommended the reason why I'm showing you all these is because if you look up 147 00:09:33,210 --> 00:09:38,940 Mac plot lib online and you find some documentation or some Stack Overflow answers you might come across 148 00:09:38,940 --> 00:09:40,140 these styles of plotting. 149 00:09:40,140 --> 00:09:44,630 So we're going to use a third method nurses recommended of course. 150 00:09:44,640 --> 00:09:48,210 You can choose your own but this is what we're going to be going through throughout the rest of the 151 00:09:48,210 --> 00:09:49,290 map Gottlieb section. 152 00:09:49,710 --> 00:09:53,880 So this is big comma acts this time. 153 00:09:53,880 --> 00:09:58,110 So we've saved a line of code equals penalty dot subplots. 154 00:09:58,110 --> 00:10:05,780 Now let's see what this says subplots create a figure and a set of subplots. 155 00:10:05,830 --> 00:10:11,590 This utility wrapper makes it convenient to create common layouts of subplots including the enclosing 156 00:10:11,590 --> 00:10:13,780 figure object in a single call. 157 00:10:13,780 --> 00:10:19,900 Now what is this subplot you could think of a subplot as having more than one plot come out at the same 158 00:10:19,900 --> 00:10:20,520 time. 159 00:10:20,530 --> 00:10:21,980 That's all it really is. 160 00:10:22,090 --> 00:10:25,840 And then we're going to go ax dot plot x y 161 00:10:28,860 --> 00:10:35,350 and some data and we'll put a little semicolon at the end instead of calling plot don't show this time. 162 00:10:35,370 --> 00:10:36,330 There we go. 163 00:10:36,440 --> 00:10:41,610 Just re created the same graph three times three different methods but we're gonna be focused on the 164 00:10:41,610 --> 00:10:49,140 third method and you might notice that every time I call something like fig eagles or ax eagles or fig 165 00:10:49,140 --> 00:10:54,140 comma ax Eagles it resets the figure even though we're plotting the same data. 166 00:10:54,180 --> 00:11:06,790 Maybe if we went here and we go 50 100 200 250 it's gonna change it up so every time we call something 167 00:11:06,790 --> 00:11:10,270 like this it's going to reset the figure and plot a new set of data. 168 00:11:10,930 --> 00:11:12,210 So let's wrap it up there. 169 00:11:12,310 --> 00:11:17,650 But in short the main takeaway from this lecture is that we're going to be focused on this method. 170 00:11:17,650 --> 00:11:23,440 There's two different types of methods plotting in that plot lib the pipeline API but that's generally 171 00:11:23,440 --> 00:11:29,490 less flexible it is quicker to get plots up and running sometimes but the object orientated API is going 172 00:11:29,490 --> 00:11:33,370 to allow us to do a bit more fancy stuff in the future so that's what we'll focus on. 173 00:11:34,150 --> 00:11:35,260 I'll see you in the next video.