And welcome back to the class of our course with the complete introduction to the science with Python.
So in this class, we are still talking about matplotlib and we are going to learn to make another type
of graph or whatever type of graph.
So basically what we are going to learn today is how we can create a histogram inside of matplotlib.
So you see, it's not really complicated and the result could be really interesting.
All right.
So basically, the first thing that we are going to do is we will import Muttalib as we always do.
We are going to create our little database, create our functions and finally give a title as well as
axis name.
So for X and Y axis name to our graph.
And finally we'll run everything and we can even play with this idea.
So let's start.
So as I said, the first thing that we are going to do, we are going to import matplotlib that pipe
plug.
So pretty simple.
Just write it down.
So import my blood Leyb dot by plot as Kielty.
So this would be the first step then, since we want to add change, the style in the future will not
do it right now.
So we'll not import the style model right now.
We'll do it a bit later when we'll finish everything.
All right.
So right now, the first thing that we are going to do, we are going to create a database.
So basically inside of a histogram, you need two things.
You need a minimum of two things.
So basically you will need your number.
So basically how a histogram works, you need a certain amount of numbers.
Let's say you have numbers one from one to let's say one hundred, and you have random numbers between
those.
This is the first step.
So we're having the random amount of numbers that are from one to one hundred, then the same thing
that you need.
You need the jumps that you want inside of your histogram.
So it could be jumps from one to 10, one to twenty, one to fifteen or whatever you guys want.
And what it's going to do, it's going to calculate how much numbers are between zero and 10, for example,
with you and 15 or so and 20, for example.
So we'll try it out and you guys will understand.
So let's write it down.
So we see the first number that we'll have.
Let's call it just numbers.
So basically, this will be our first list.
We'll call it numbers.
And basically, here's what I want you guys to do, is simply write down random numbers that are between
one and it could well want 100.
So basically, you can write down as much numbers as you guys want.
It's just, for example, purposes.
And those numbers could be any numbers that you want.
So just don't make a mistake and write down two or three commas because it's not going to be really
nice.
So here we go.
I think I have enough numbers.
All right.
Next thing I want to do is we need jumps.
So basically we want jumps of five one jumps of 10, one jumps above.
We decide what type of chance of jumps that we want.
And basically this would be how our histogram will be wide or small, basically.
So let's write it down.
So basically here, let's call it jumps.
So let's write it down, so basically for jumps would be somewhere between, let's say it's going to
be from one to 15, so write it down.
So it's going to be zero.
Then we'll have 15.
Then we'll have 30.
Then we'll have 45.
Then we'll have 60, 70, five, nine.
And finally, one hundred and five.
All right.
So right now we have our numbers and we have our jumps.
The next thing that we need to do is pretty simple.
We need to create a title for our histogram or our graph.
So, as always, will create a title.
So let's call it in this case or the title.
And here let's call it we can call it whatever you want.
I'll call it the test.
One is since we're making a histogram in this case.
All right, then we will need the label.
So basically for Xs we'll need a label for why it's illegal.
So that, as always, X label.
So how we want to call or exs, let's call it test X.
Label and for whites, it's going to be pretty much the same thing, so Kielty that white label.
And we'll call it test y label here.
So we have everything that we need.
So basically until now, we have everything that we need to be able to create our histogram.
Now it's time to run everything and to see what it all looks like.
So basically to run everything, simply write down that show as we always do, open and close the parenthesis
and you can run everything.
So here we go.
Oh, we forgot a little part of the code, so we need to write down the functions that we make everything
work.
So basically without this function, nothing would work.
It's pretty simple.
So we need to write down our function for our histogram.
So Kielty, in this case, that highest.
So when we have our function for a histogram and how exactly works.
So basically there are four arguments inside of it, but we are only going to write down three arguments,
which would be so the first argument is pretty simple is the numbers that we have.
So basically all the numbers that we have here and in this case will just write down the numbers.
The second argument will be the jumps that are histogram inside of histogram will happen.
So basically we will have jumps of 15 in this case.
So our second argument will be jumps.
The third argument will be the histogram type.
So basically, what is the type of histogram that we have?
So we see there are plenty of types of histogram that exist.
So we'll use Bari's for steps.
Obviously, this would be the two types of histogram that we are going to see today.
But if you guys want to learn some more types of histogram, you can just Google it.
You'll receive all the histogram types that exist.
So let's write it down.
So it's going to be the highest type.
It's the one right here.
And from this moment, we'll just write down, for example, bar since we want to receive burse.
And basically, this is the type of Instagram that will receive by default, so just right, no.
All right.
So when we have everything, Suzanne, right now, we have absolutely everything we have our database
for right here.
We have our title right there.
We have our function right here that is ready to be run.
And finally, we have our potential so we can run everything and see what it looks like.
So you can see this is what our Instagram looks like.
So basically, we have this one, Instagram, which is the name of our Instagram.
We have the white label right here.
We have the X label right here, as we said.
So basically the X axis and the Y axis.
So our Instagram is pretty much ready and works well.
If you want to change the jumps, we can change the jumps right here.
If we want to change the numbers that we have, we can do it right there.
And basically what we can understand from this Instagram, for example, if we look from zero to 15,
we know that there is five numbers that are between zero and 15.
We know that there is nine numbers that are from 15 to 30.
And we know that there is only one number that is between 30 and 45.
This is what we understand from this Instagram when I'm talking about histogram type.
So as I said, we have bars, but we have plenty of others.
So another one that is really interesting would be the Steph.
Works pretty much the same way, so you can see those are steps, it's not as well as beautiful, in
my opinion, but once again, this is another type of Instagram that you guys can have.
All right.
So as always, what we can do with this type of graph, we can change the style and exactly what we'll
do right now.
So just for you guys to practice a little bit.
So what we'll do, we'll just import the sub package also from my lab import stuff.
So if we want to import the style stuff package and want to do right now is just change their style.
So basically we will change the style by writing down style that use and from this moment, just write
down the type of style that you guys want.
So let's try the style and run everything to see what it all looks like.
Right.
As you can see, this is what it looks like with the image.
So the graph becomes a little bit different.
So as you can see, this is how you guys can generate a histogram inside of Python with the use of matplotlib.
And once again, this is a powerful tool.
What the histogram is a powerful tool to be able to help you visualize your data.
So it's a process that goes into our next class.