1 00:00:00,060 --> 00:00:05,380 And welcome back to the class of our course with the complete introduction to the science with Python. 2 00:00:05,880 --> 00:00:12,780 So in this class, we are still talking about matplotlib and we are going to learn to make another type 3 00:00:12,780 --> 00:00:16,230 of graph or whatever type of graph. 4 00:00:16,710 --> 00:00:22,400 So basically what we are going to learn today is how we can create a histogram inside of matplotlib. 5 00:00:22,680 --> 00:00:27,180 So you see, it's not really complicated and the result could be really interesting. 6 00:00:28,020 --> 00:00:28,320 All right. 7 00:00:28,330 --> 00:00:33,270 So basically, the first thing that we are going to do is we will import Muttalib as we always do. 8 00:00:33,390 --> 00:00:40,290 We are going to create our little database, create our functions and finally give a title as well as 9 00:00:40,950 --> 00:00:41,700 axis name. 10 00:00:42,420 --> 00:00:46,290 So for X and Y axis name to our graph. 11 00:00:46,920 --> 00:00:50,520 And finally we'll run everything and we can even play with this idea. 12 00:00:51,030 --> 00:00:51,850 So let's start. 13 00:00:51,870 --> 00:00:57,820 So as I said, the first thing that we are going to do, we are going to import matplotlib that pipe 14 00:00:57,840 --> 00:00:58,120 plug. 15 00:00:58,470 --> 00:00:59,340 So pretty simple. 16 00:00:59,340 --> 00:01:00,120 Just write it down. 17 00:01:00,120 --> 00:01:10,260 So import my blood Leyb dot by plot as Kielty. 18 00:01:11,100 --> 00:01:19,800 So this would be the first step then, since we want to add change, the style in the future will not 19 00:01:19,800 --> 00:01:20,400 do it right now. 20 00:01:20,400 --> 00:01:22,680 So we'll not import the style model right now. 21 00:01:22,800 --> 00:01:25,080 We'll do it a bit later when we'll finish everything. 22 00:01:25,920 --> 00:01:26,270 All right. 23 00:01:26,280 --> 00:01:30,820 So right now, the first thing that we are going to do, we are going to create a database. 24 00:01:30,820 --> 00:01:34,230 So basically inside of a histogram, you need two things. 25 00:01:34,230 --> 00:01:35,720 You need a minimum of two things. 26 00:01:36,150 --> 00:01:37,590 So basically you will need your number. 27 00:01:37,620 --> 00:01:42,060 So basically how a histogram works, you need a certain amount of numbers. 28 00:01:42,060 --> 00:01:48,450 Let's say you have numbers one from one to let's say one hundred, and you have random numbers between 29 00:01:48,450 --> 00:01:48,660 those. 30 00:01:49,530 --> 00:01:50,430 This is the first step. 31 00:01:50,460 --> 00:01:56,670 So we're having the random amount of numbers that are from one to one hundred, then the same thing 32 00:01:56,670 --> 00:01:57,350 that you need. 33 00:01:57,360 --> 00:02:00,480 You need the jumps that you want inside of your histogram. 34 00:02:00,480 --> 00:02:05,490 So it could be jumps from one to 10, one to twenty, one to fifteen or whatever you guys want. 35 00:02:05,760 --> 00:02:11,400 And what it's going to do, it's going to calculate how much numbers are between zero and 10, for example, 36 00:02:11,410 --> 00:02:14,110 with you and 15 or so and 20, for example. 37 00:02:14,550 --> 00:02:16,980 So we'll try it out and you guys will understand. 38 00:02:17,970 --> 00:02:20,190 So let's write it down. 39 00:02:20,190 --> 00:02:22,170 So we see the first number that we'll have. 40 00:02:23,070 --> 00:02:24,690 Let's call it just numbers. 41 00:02:24,720 --> 00:02:26,640 So basically, this will be our first list. 42 00:02:26,650 --> 00:02:27,720 We'll call it numbers. 43 00:02:28,500 --> 00:02:33,900 And basically, here's what I want you guys to do, is simply write down random numbers that are between 44 00:02:33,900 --> 00:02:37,060 one and it could well want 100. 45 00:02:37,560 --> 00:02:41,140 So basically, you can write down as much numbers as you guys want. 46 00:02:41,370 --> 00:02:43,950 It's just, for example, purposes. 47 00:02:43,950 --> 00:02:46,560 And those numbers could be any numbers that you want. 48 00:02:47,550 --> 00:02:53,580 So just don't make a mistake and write down two or three commas because it's not going to be really 49 00:02:53,580 --> 00:02:53,910 nice. 50 00:02:55,770 --> 00:02:56,630 So here we go. 51 00:02:56,910 --> 00:02:58,410 I think I have enough numbers. 52 00:02:58,560 --> 00:02:58,990 All right. 53 00:02:59,010 --> 00:03:02,060 Next thing I want to do is we need jumps. 54 00:03:02,060 --> 00:03:07,110 So basically we want jumps of five one jumps of 10, one jumps above. 55 00:03:07,470 --> 00:03:10,170 We decide what type of chance of jumps that we want. 56 00:03:10,560 --> 00:03:16,110 And basically this would be how our histogram will be wide or small, basically. 57 00:03:16,920 --> 00:03:18,190 So let's write it down. 58 00:03:18,210 --> 00:03:20,250 So basically here, let's call it jumps. 59 00:03:22,610 --> 00:03:26,930 So let's write it down, so basically for jumps would be somewhere between, let's say it's going to 60 00:03:26,930 --> 00:03:30,640 be from one to 15, so write it down. 61 00:03:30,650 --> 00:03:31,820 So it's going to be zero. 62 00:03:32,240 --> 00:03:33,620 Then we'll have 15. 63 00:03:34,640 --> 00:03:35,870 Then we'll have 30. 64 00:03:36,390 --> 00:03:38,120 Then we'll have 45. 65 00:03:38,630 --> 00:03:42,910 Then we'll have 60, 70, five, nine. 66 00:03:43,490 --> 00:03:45,720 And finally, one hundred and five. 67 00:03:47,000 --> 00:03:47,380 All right. 68 00:03:47,390 --> 00:03:49,750 So right now we have our numbers and we have our jumps. 69 00:03:50,510 --> 00:03:53,420 The next thing that we need to do is pretty simple. 70 00:03:53,420 --> 00:03:58,220 We need to create a title for our histogram or our graph. 71 00:03:58,580 --> 00:04:00,380 So, as always, will create a title. 72 00:04:00,740 --> 00:04:05,230 So let's call it in this case or the title. 73 00:04:06,950 --> 00:04:09,680 And here let's call it we can call it whatever you want. 74 00:04:09,680 --> 00:04:11,060 I'll call it the test. 75 00:04:11,960 --> 00:04:15,380 One is since we're making a histogram in this case. 76 00:04:16,580 --> 00:04:18,620 All right, then we will need the label. 77 00:04:18,630 --> 00:04:22,070 So basically for Xs we'll need a label for why it's illegal. 78 00:04:22,070 --> 00:04:25,910 So that, as always, X label. 79 00:04:27,940 --> 00:04:33,400 So how we want to call or exs, let's call it test X. 80 00:04:35,080 --> 00:04:41,890 Label and for whites, it's going to be pretty much the same thing, so Kielty that white label. 81 00:04:43,420 --> 00:04:49,610 And we'll call it test y label here. 82 00:04:49,850 --> 00:04:51,080 So we have everything that we need. 83 00:04:51,520 --> 00:04:55,570 So basically until now, we have everything that we need to be able to create our histogram. 84 00:04:55,900 --> 00:04:59,240 Now it's time to run everything and to see what it all looks like. 85 00:04:59,260 --> 00:05:06,280 So basically to run everything, simply write down that show as we always do, open and close the parenthesis 86 00:05:06,490 --> 00:05:08,200 and you can run everything. 87 00:05:08,920 --> 00:05:09,730 So here we go. 88 00:05:12,450 --> 00:05:19,860 Oh, we forgot a little part of the code, so we need to write down the functions that we make everything 89 00:05:19,860 --> 00:05:20,130 work. 90 00:05:20,130 --> 00:05:22,900 So basically without this function, nothing would work. 91 00:05:22,920 --> 00:05:23,780 It's pretty simple. 92 00:05:24,360 --> 00:05:26,850 So we need to write down our function for our histogram. 93 00:05:26,850 --> 00:05:29,400 So Kielty, in this case, that highest. 94 00:05:30,180 --> 00:05:34,390 So when we have our function for a histogram and how exactly works. 95 00:05:34,410 --> 00:05:38,820 So basically there are four arguments inside of it, but we are only going to write down three arguments, 96 00:05:39,510 --> 00:05:43,510 which would be so the first argument is pretty simple is the numbers that we have. 97 00:05:43,530 --> 00:05:48,960 So basically all the numbers that we have here and in this case will just write down the numbers. 98 00:05:50,550 --> 00:05:56,270 The second argument will be the jumps that are histogram inside of histogram will happen. 99 00:05:56,280 --> 00:05:59,140 So basically we will have jumps of 15 in this case. 100 00:05:59,700 --> 00:06:01,860 So our second argument will be jumps. 101 00:06:02,700 --> 00:06:05,520 The third argument will be the histogram type. 102 00:06:05,540 --> 00:06:08,000 So basically, what is the type of histogram that we have? 103 00:06:08,310 --> 00:06:10,730 So we see there are plenty of types of histogram that exist. 104 00:06:10,740 --> 00:06:12,400 So we'll use Bari's for steps. 105 00:06:12,430 --> 00:06:16,850 Obviously, this would be the two types of histogram that we are going to see today. 106 00:06:17,340 --> 00:06:21,210 But if you guys want to learn some more types of histogram, you can just Google it. 107 00:06:21,210 --> 00:06:24,170 You'll receive all the histogram types that exist. 108 00:06:24,780 --> 00:06:25,780 So let's write it down. 109 00:06:25,800 --> 00:06:27,500 So it's going to be the highest type. 110 00:06:27,510 --> 00:06:28,770 It's the one right here. 111 00:06:29,220 --> 00:06:33,630 And from this moment, we'll just write down, for example, bar since we want to receive burse. 112 00:06:34,640 --> 00:06:40,160 And basically, this is the type of Instagram that will receive by default, so just right, no. 113 00:06:40,550 --> 00:06:40,900 All right. 114 00:06:40,970 --> 00:06:44,990 So when we have everything, Suzanne, right now, we have absolutely everything we have our database 115 00:06:44,990 --> 00:06:45,830 for right here. 116 00:06:46,460 --> 00:06:48,650 We have our title right there. 117 00:06:49,130 --> 00:06:52,150 We have our function right here that is ready to be run. 118 00:06:52,280 --> 00:06:57,740 And finally, we have our potential so we can run everything and see what it looks like. 119 00:06:58,500 --> 00:07:01,380 So you can see this is what our Instagram looks like. 120 00:07:01,400 --> 00:07:05,630 So basically, we have this one, Instagram, which is the name of our Instagram. 121 00:07:06,350 --> 00:07:08,320 We have the white label right here. 122 00:07:08,330 --> 00:07:11,270 We have the X label right here, as we said. 123 00:07:11,270 --> 00:07:13,920 So basically the X axis and the Y axis. 124 00:07:14,600 --> 00:07:19,370 So our Instagram is pretty much ready and works well. 125 00:07:20,180 --> 00:07:23,360 If you want to change the jumps, we can change the jumps right here. 126 00:07:23,360 --> 00:07:26,290 If we want to change the numbers that we have, we can do it right there. 127 00:07:26,840 --> 00:07:32,090 And basically what we can understand from this Instagram, for example, if we look from zero to 15, 128 00:07:32,090 --> 00:07:35,570 we know that there is five numbers that are between zero and 15. 129 00:07:36,020 --> 00:07:39,940 We know that there is nine numbers that are from 15 to 30. 130 00:07:40,280 --> 00:07:44,330 And we know that there is only one number that is between 30 and 45. 131 00:07:44,900 --> 00:07:49,940 This is what we understand from this Instagram when I'm talking about histogram type. 132 00:07:49,960 --> 00:07:52,380 So as I said, we have bars, but we have plenty of others. 133 00:07:52,400 --> 00:07:55,310 So another one that is really interesting would be the Steph. 134 00:07:56,340 --> 00:08:02,430 Works pretty much the same way, so you can see those are steps, it's not as well as beautiful, in 135 00:08:02,430 --> 00:08:07,150 my opinion, but once again, this is another type of Instagram that you guys can have. 136 00:08:07,860 --> 00:08:08,240 All right. 137 00:08:08,250 --> 00:08:14,940 So as always, what we can do with this type of graph, we can change the style and exactly what we'll 138 00:08:14,940 --> 00:08:15,800 do right now. 139 00:08:15,810 --> 00:08:17,980 So just for you guys to practice a little bit. 140 00:08:18,300 --> 00:08:27,950 So what we'll do, we'll just import the sub package also from my lab import stuff. 141 00:08:28,020 --> 00:08:34,270 So if we want to import the style stuff package and want to do right now is just change their style. 142 00:08:34,290 --> 00:08:41,730 So basically we will change the style by writing down style that use and from this moment, just write 143 00:08:41,730 --> 00:08:43,860 down the type of style that you guys want. 144 00:08:43,890 --> 00:08:49,290 So let's try the style and run everything to see what it all looks like. 145 00:08:50,290 --> 00:08:50,570 Right. 146 00:08:50,640 --> 00:08:53,530 As you can see, this is what it looks like with the image. 147 00:08:53,550 --> 00:08:56,130 So the graph becomes a little bit different. 148 00:08:56,160 --> 00:09:02,290 So as you can see, this is how you guys can generate a histogram inside of Python with the use of matplotlib. 149 00:09:02,730 --> 00:09:04,880 And once again, this is a powerful tool. 150 00:09:04,890 --> 00:09:08,670 What the histogram is a powerful tool to be able to help you visualize your data. 151 00:09:09,060 --> 00:09:12,510 So it's a process that goes into our next class.