Hello, guys, and welcome back to our class of our course about the complete introduction to the science
with the use of Python in this class, we are still talking about matplotlib and we are going to learn
how to create another type of chart.
So basically we are going to create another type of graph chart and that the one will be the big picture.
So basically we are going to create a PI that will give a piece for each element that will have inside
of our chart.
So you'll see it's pretty simple to make.
It's not that hard, but it's a bit different.
So the first part of the course we are going to import matplotlib as we always do, then we are going
to create arguments that we are going to use.
We will have our arguments will simply create the function.
So we'll use the PI function in this case.
Finally, we'll give a title to our chart and show everything to to visualize that.
And by the end, we'll also play with the style of this graph.
So let's start.
So I said the first thing that we will do is we will import matplotlib.
So that block.
That dog fight a lot, so when everything is imported,
so everything is important.
The second thing that we'll do is that we are going to work with the arguments that we will.
So basically, for the purpose of discourse, what I can what I prepared is pretty simple.
We are going to work with a basic example.
So we'll have food that will be sold and basically will calculate the number of sales and the food that
has been sold.
And we'll give each type of food a certain color.
So let's do it.
So basically, we'll start with writing down the foods that we have.
So we have our food right here and what exactly we have like food.
So we will have, let's say, pizza.
We will have ice cream.
And finally, we will have, let's say, burgers, so as you can see, pretty simple, so we have three
types of food.
The same thing that we'll need is the sales for each one.
So basically, let's say we have sold out on know let's say we have sold 20 pizzas.
We have sold what else?
We have sold 10 ice creams and we have sold 30 burgers.
All right, and finally, the last thing that we will need is the colors.
So basically what color, what color will be used for each of those things?
So in this case, pretty simple for pizza.
Let's say it's going to be red.
For ice cream, let's say it's going to be blue and finally for burgers, let's say it's going to be
yellow.
All right.
So we have everything that we need for our pie chart.
So basically, we have our types of food that we will use.
We have the sales that have been made for each type of food.
And finally, the color for each type of food that we have.
So let's write down the functions.
It's pretty simple.
It's going to be pretty that by since we're that's a pie chart.
So the first part of it will be the what are the numbers that we have sold.
So basically, this is the first part and the numbers are in the variable sales.
So we'll just write down sales right here.
Then the second element of the variable will be the colors or the type of food.
So basically in this case, we are going to use the type of food.
So it's called labels.
So what are the labels that we are?
What are the labels?
That's the one right here.
Right.
So what exactly are the labels that we are going to give to each part of our picture?
So in this case, the labels will be pizza, ice cream, as well as burgers.
And the labels are inside of the variable food food.
Finally, the last variable that we will need will be the color viable.
So in this case, what each label will have like a color.
So what color will have?
So in this case, it's pretty simple.
It's called colors.
And the label, the color is a variable right here will be linked with the variable color, will just
write down color.
All right.
So we have everything that we need and now it's time to run that well.
Now it's time to give it title to our church.
So let's just give it a title.
So let's name an example, for just example.
All right, so right now we have the title of our chart listing that we have left to do is simply see
what it all looks like.
So we will run everything.
I just ran without that show.
And as you can see, this is our pie chart that we have.
So if we compare what we have right here with answers, so basically we have our title that is example,
food.
We have pizza, which is the first one, and has twenty sales, which is the second biggest one.
We have burgers, which is the half of the pie.
So in this case, 30 sales.
And finally, as ice cream only has 10 sales is the lowest one right there.
So everything makes sense.
All right.
So right now that everything works, we can play with the style.
So once again, this is what we will do.
So we'll import the sub package styles.
So just write down from my blood glib import.
Style and what we'll do right now, we'll just add a style to our charts, we'll just write down style
use and we can choose the type of style that we want for this class.
We can use classic.
This is one type of one style that exists.
So if everything as you can see, it became a bit different.
The background became great.
So basically, this is another style that can be used.
So if you guys want to change, for example, the numbers right here put let's say 15 instead of 10,
you can do it if you want to change the color instead of blue, putting green, for example, you can
do it as well.
And if you run the app, you'll see it's going to automatically adapt.
So you can see it's pretty simple.
And this is an amazing visual visual, too.
So basically it allows you to see visually your data and be able to get the answers that you need pretty
easy.
So that's a first class guys and all our next class.