1 00:00:00,860 --> 00:00:07,380 In the NUM pi section we talked about how many Python data science packages are built off. 2 00:00:07,480 --> 00:00:08,740 PI a raise. 3 00:00:08,740 --> 00:00:14,890 The same goes for Matlock lib and one of the beautiful things about map plot lib is it's about as flexible 4 00:00:14,890 --> 00:00:18,960 as an umpire raise if you can dream up a way to visualize data. 5 00:00:19,060 --> 00:00:25,450 Chances are you can do it in map plot lib but there are some common kinds of visualizations and others 6 00:00:25,690 --> 00:00:32,470 or some more common ones you're more likely to come across and these plots are the ones like line scatter 7 00:00:32,530 --> 00:00:38,020 bar haste and subplots or plotting multiple visualizations on one finger. 8 00:00:38,020 --> 00:00:42,360 Let's have a look at some of these kinds of plots that you'll see more often plots of figures. 9 00:00:42,370 --> 00:00:44,530 Remember that words kind of interchangeable. 10 00:00:44,530 --> 00:00:48,250 Using pure num pi arrays so started off. 11 00:00:48,310 --> 00:00:59,950 So we making figures with NUM pi arrays will make this mark down so it's a little bit communicative 12 00:01:00,010 --> 00:01:01,170 and then we'll go import. 13 00:01:01,210 --> 00:01:03,160 If you haven't already done this we've done this at the top. 14 00:01:03,160 --> 00:01:03,940 I will do it again. 15 00:01:03,940 --> 00:01:06,860 Import num pi as MP. 16 00:01:06,870 --> 00:01:11,380 I will start off by create some data. 17 00:01:11,380 --> 00:01:19,630 X equals NDP dot Lin space 0 10 one hundred maybe go on hold on Daniel. 18 00:01:19,630 --> 00:01:21,460 We haven't seen Lin space. 19 00:01:21,610 --> 00:01:25,550 Well in that case remember what can you do. 20 00:01:25,570 --> 00:01:26,900 Did you get it. 21 00:01:26,920 --> 00:01:28,540 Well if you did it doesn't matter. 22 00:01:28,540 --> 00:01:32,510 We can press shift tab and see what Lin space actually does. 23 00:01:34,140 --> 00:01:36,230 To an MP Lin space. 24 00:01:36,390 --> 00:01:43,590 The start stop numb the case then the first three arguments we've got zero start tennis stop 100 as 25 00:01:43,580 --> 00:01:44,120 now. 26 00:01:44,130 --> 00:01:45,390 All right well let's have a look. 27 00:01:45,420 --> 00:01:50,190 Return evenly spaced numbers over a specified interval. 28 00:01:50,190 --> 00:01:54,690 Returns num evenly spaced samples calculated over the interval start stop. 29 00:01:54,690 --> 00:02:00,410 So it's gonna return num evenly spaced intervals between start and stops. 30 00:02:00,420 --> 00:02:01,980 What do you think will happen here. 31 00:02:01,980 --> 00:02:05,310 Well if in doubt run the code let's check it out. 32 00:02:06,190 --> 00:02:09,100 Well there's gonna be 100 samples so we don't see all that. 33 00:02:09,100 --> 00:02:12,280 Let's see the first 10 wonderful. 34 00:02:12,330 --> 00:02:16,850 Well let's say the first one hundred one on I'm going to taking risk aren't you. 35 00:02:16,860 --> 00:02:18,090 So there we go. 36 00:02:18,160 --> 00:02:25,360 We've got 100 different samples here 100 different floats values here between 0 and 10. 37 00:02:25,360 --> 00:02:26,240 So we start at zero. 38 00:02:26,260 --> 00:02:31,590 Goes all the way up to 10 wonderful or reduces back to 10 to save some space. 39 00:02:31,600 --> 00:02:32,410 Excellent. 40 00:02:32,410 --> 00:02:36,350 Now let's go plot the data. 41 00:02:36,460 --> 00:02:42,280 So remember we're going to create a fig and an ax or figure and axes but these are the common short 42 00:02:42,280 --> 00:02:48,840 names figure in accessing go plot subplots because this is the method that we're gonna be using axe 43 00:02:48,910 --> 00:02:55,770 stop plot x and let's do because plot takes x and y but we don't have a Y. 44 00:02:55,810 --> 00:02:58,780 Let's just do X to the power of two. 45 00:02:58,840 --> 00:03:00,690 Well let's see what happens. 46 00:03:00,700 --> 00:03:05,850 We'll put a little semicolon wonderful we get this beautiful curve line. 47 00:03:05,980 --> 00:03:11,650 So the default here in that plot layer when you call plot is a line plot. 48 00:03:11,650 --> 00:03:13,120 This a line plot. 49 00:03:13,120 --> 00:03:18,210 So and create a line plot area. 50 00:03:18,310 --> 00:03:20,610 So as you can see just a straight line. 51 00:03:20,780 --> 00:03:23,080 Now use the same data. 52 00:03:23,110 --> 00:03:24,850 Let's create a scatter plot. 53 00:03:24,880 --> 00:03:27,950 Use the same data because it's the most common types. 54 00:03:27,970 --> 00:03:29,940 Let's write these down. 55 00:03:30,190 --> 00:03:30,880 We want 56 00:03:34,530 --> 00:03:48,360 fly plot scatter plot bar plot history and history show for histogram and a subplot. 57 00:03:48,440 --> 00:03:50,890 They're the main types of plots we're gonna be focused on. 58 00:03:51,000 --> 00:03:56,040 Of course there are more but we could we go on all year for the amount of plot you could do a map plot 59 00:03:56,040 --> 00:03:56,300 lib. 60 00:03:56,310 --> 00:04:03,110 So we'll focus on the baseline ones and then you can build upon that knowledge so we want you same data 61 00:04:03,620 --> 00:04:06,210 to make a scatter plot. 62 00:04:06,500 --> 00:04:07,670 See what a scatter plot is. 63 00:04:07,670 --> 00:04:12,010 So if we want to recreate it we have to always reset fig and ax. 64 00:04:12,140 --> 00:04:17,100 If we're in a different cell equals P LTM subplots. 65 00:04:17,750 --> 00:04:18,680 Wonderful acts. 66 00:04:18,710 --> 00:04:26,200 Now we're gonna scatter so here we use dot plot but if we want to scatter plot we'll see what that looks 67 00:04:26,200 --> 00:04:27,190 like in a second. 68 00:04:27,190 --> 00:04:30,300 We need to call dot scatter on ax. 69 00:04:30,370 --> 00:04:31,660 So here we go. 70 00:04:31,690 --> 00:04:34,360 I want X and then we want end p. 71 00:04:34,540 --> 00:04:36,970 We'll do the exponential all x. 72 00:04:37,060 --> 00:04:40,560 And remember if you're not sure what he XP means you can go shift tab. 73 00:04:40,870 --> 00:04:47,190 Read the docs string here what it says it is and if it's still not clear you can look up the documentation. 74 00:04:48,760 --> 00:04:49,420 There we go. 75 00:04:49,570 --> 00:04:55,300 Well it's kind of like a line but a scatter plot is just another word for lots of dots on the plot. 76 00:04:55,300 --> 00:05:01,450 These are really close together these dots so they kind of look like a line but they are all just dots. 77 00:05:01,690 --> 00:05:02,070 All right. 78 00:05:02,260 --> 00:05:06,890 Well how about another set upon let's make another one. 79 00:05:06,900 --> 00:05:09,440 Just so we can see fig acts. 80 00:05:09,460 --> 00:05:16,090 I want you to get really used to typing out this thing X P L T dot subplots this is gonna be our bread 81 00:05:16,090 --> 00:05:23,740 and butter from that plot lib acts dot scatter x let's create a wave because we did one of those before 82 00:05:23,740 --> 00:05:24,870 and that was my joke. 83 00:05:26,090 --> 00:05:27,140 Beautiful. 84 00:05:27,200 --> 00:05:29,960 So we got a nice little wife here and if you're not sure what this is. 85 00:05:29,960 --> 00:05:31,610 Well this is a sine wave. 86 00:05:31,610 --> 00:05:35,360 And again you can always see the dock string or look it up. 87 00:05:35,360 --> 00:05:41,320 No this stamps you can search it off if you're still not sure after looking that use a num ply arrays 88 00:05:41,330 --> 00:05:46,640 and that's what this section is making figures an umpire raise how about we create a plot directly from 89 00:05:46,640 --> 00:05:47,910 a dictionary. 90 00:05:47,910 --> 00:05:56,450 So make a plot from a dictionary because this is just showing how versatile a flexible map plop live 91 00:05:56,450 --> 00:05:57,050 is. 92 00:05:57,050 --> 00:06:00,000 So if we want my arm and by the stall we'll bring that back. 93 00:06:00,080 --> 00:06:02,430 So we want not by the prices. 94 00:06:02,450 --> 00:06:04,000 That's my favorite food. 95 00:06:04,070 --> 00:06:04,610 Do you like it. 96 00:06:05,360 --> 00:06:06,020 I like it too. 97 00:06:06,500 --> 00:06:09,360 So we want here one by 10. 98 00:06:09,470 --> 00:06:10,300 It's quite expensive. 99 00:06:10,310 --> 00:06:10,990 Peanut butter. 100 00:06:11,000 --> 00:06:11,960 Not as expensive. 101 00:06:11,960 --> 00:06:12,900 Where I live. 102 00:06:13,250 --> 00:06:19,620 So aid and cash about is the most expensive cashews are hard to come by you know in short supply sometimes. 103 00:06:19,640 --> 00:06:26,090 So if I go here and then we've got fig X equals BLT or subplots we're getting really good at this one 104 00:06:26,450 --> 00:06:28,980 and now we want let's do a bar plot this time. 105 00:06:29,000 --> 00:06:35,420 So yeah I the trend we're changing this now I know it's kind of confusing because there's a line plot 106 00:06:35,450 --> 00:06:39,950 but it says plot doesn't say line you're just gonna have to get used to the fact that the default map 107 00:06:39,950 --> 00:06:46,040 plot lib is a line plot but now we're going to create a bar plot so acts dot bar and we're going to 108 00:06:46,040 --> 00:06:54,710 pass it x and y so X maybe we'll be a bit more formal X equals nut butter prices what do we want we 109 00:06:54,710 --> 00:06:59,960 want the keys from our dictionary because we're using a dictionary now not known by array so you want 110 00:06:59,960 --> 00:07:08,270 the keys here and our y value so we'll type in y that's what plot or bar or scatter always take X and 111 00:07:08,270 --> 00:07:18,620 Y might put that a little comment x y not but our prices dot values beautiful and now we might see what 112 00:07:18,620 --> 00:07:21,720 this looks like huh era. 113 00:07:21,800 --> 00:07:23,020 Missing argument. 114 00:07:23,020 --> 00:07:24,050 Right. 115 00:07:24,050 --> 00:07:26,370 Huh that's interesting. 116 00:07:26,480 --> 00:07:26,990 I see this. 117 00:07:26,990 --> 00:07:31,190 This one doesn't take why that's a problem positional argument. 118 00:07:31,200 --> 00:07:32,180 Keyword found. 119 00:07:32,300 --> 00:07:34,640 What if we get rid of this. 120 00:07:34,850 --> 00:07:35,630 My bad. 121 00:07:35,630 --> 00:07:44,210 This doesn't take X and Y see you're learning something new every day shift type x is x x equals that 122 00:07:45,640 --> 00:07:47,750 and so we can't have we can't have that equaling that. 123 00:07:47,930 --> 00:07:52,910 So we're going to leave this at that act stop our shift tab. 124 00:07:53,110 --> 00:07:59,440 So this is a little Python thing if you haven't seen this before it's a syntax error where in a python 125 00:07:59,440 --> 00:08:06,220 method if you have a positional argument say x equals this you need something after it to go like say 126 00:08:06,220 --> 00:08:13,690 Y equals this you can't have X equals something and then followed by that but you can have it the other 127 00:08:13,690 --> 00:08:16,680 way round so see how we don't have x equals. 128 00:08:16,780 --> 00:08:21,360 We can't have this bean height equals it'll come out the same thing. 129 00:08:21,370 --> 00:08:26,290 So the first one can't have positional argument where the second one doesn't. 130 00:08:26,320 --> 00:08:28,900 But the second one can and the first one doesn't have to. 131 00:08:28,930 --> 00:08:30,990 That's a little bit of a python tidbit there. 132 00:08:31,020 --> 00:08:33,080 So getting a lot of value from this map plot. 133 00:08:33,090 --> 00:08:34,220 He likes it here. 134 00:08:34,330 --> 00:08:36,300 Now this doesn't really make sense. 135 00:08:36,310 --> 00:08:37,300 We've got a few bars here. 136 00:08:37,300 --> 00:08:40,130 You can kind of infer that that's prices. 137 00:08:40,180 --> 00:08:41,470 That's customize it. 138 00:08:41,470 --> 00:08:50,920 Let's add a little bit of a title may want and not about our prices store and see that little exploration 139 00:08:50,920 --> 00:08:52,160 that we just did before. 140 00:08:52,270 --> 00:08:53,350 That's gonna happen right. 141 00:08:53,350 --> 00:08:58,630 You're gonna make mistakes you're gonna think you know things like me and then you're gonna go oh that's 142 00:08:58,630 --> 00:09:02,860 actually not like that and then you look at the dock string you'll fix it up and you'll combine your 143 00:09:02,860 --> 00:09:05,670 previous knowledge and go oh that's why that's like that. 144 00:09:05,740 --> 00:09:08,690 So don't worry if it happens to you it happens to me. 145 00:09:08,840 --> 00:09:12,410 Why label your price. 146 00:09:12,580 --> 00:09:17,710 But what we do is we strive forward and we figure things out shift into. 147 00:09:17,830 --> 00:09:18,640 There we go. 148 00:09:18,640 --> 00:09:19,660 That looks a bit better. 149 00:09:19,690 --> 00:09:23,620 And what can we do to remove that ugly line of text there. 150 00:09:23,620 --> 00:09:25,620 I believe we can do X not show. 151 00:09:25,980 --> 00:09:26,280 Nope. 152 00:09:26,300 --> 00:09:30,970 Well that has no attribute called show but we can add a semicolon up. 153 00:09:31,220 --> 00:09:37,270 Yeah I believe or maybe down here yeah okay there we go. 154 00:09:37,300 --> 00:09:38,870 So we're learning on the fly here. 155 00:09:38,980 --> 00:09:44,470 If you want to remove that nasty line of output code you can add a semicolon to the last line where 156 00:09:44,470 --> 00:09:45,280 you call ax. 157 00:09:45,280 --> 00:09:49,020 We've seen this semicolon before but we've just seen where you actually have to put it. 158 00:09:49,030 --> 00:09:52,060 It's on the last line where you reference ax. 159 00:09:52,150 --> 00:09:53,440 There we go. 160 00:09:53,530 --> 00:09:55,040 You can create your own store. 161 00:09:55,060 --> 00:09:58,210 We've just seen had a plot from num PI a raise. 162 00:09:58,300 --> 00:10:02,100 We'll look at a little bit more in the next video but to prevent this one from getting too long. 163 00:10:02,110 --> 00:10:03,340 We'll pause it here. 164 00:10:03,490 --> 00:10:04,820 So take a little break. 165 00:10:04,900 --> 00:10:09,100 Create your own plot from a dictionary or a nun pie array and I'll see you shortly.