Annotating Charts in Matplotlib

preview_player
Показать описание

TRANSCRIPT

In this video, we are going to make our plot look a bit better and then add things like labels on the axes, and the title, so we can have a look at function on plot called title that I can add, and you can look at the documentation for there's a bunch of other arguments that you can go with this. But we will just say, let's give it a simple title. So number of fruit sold 2017. So here in the figure that shows up, we have a title at the very top here. There are other configuration options as to where do you wanna put the title. The other thing that we want to do is set a title or a axis label for the y-axis, y-label, and that will label the y-axis for us. So I can say number of fruit, and this will be in the millions. And we see that on the left, you see that there is the Number of fruit (millions) label on the y-axis. The one last thing that we need to do is set up the x-axis so that instead of saying 0, 1, 2, 3, 4, we use the actual fruit xticks. We are essentially going to take the numbers and replace them with ticks. So we need to tell matplotlib which of the numbers we wanna replace and what we wanna replace them with. So we wanna replace these r-coordinates here with the fruit here. So if I run this guy again, you see that now, we have replaced the 0, 1, 2, 3, 4 with the actual names of the fruits, and we have a completed chart here. So you can see that apples sold the most and grapefruits apparently didn't quite sell as much, and oranges and bananas were very close, pears were a little bit more, but not quite as much as apples. So using this bar chart, we can look at different kinds of information and gain some insights out of this. So these kinds of column charts are great or categorical data, so here in the x-axis, we have categories, and then we have a numerical value assigned to each category. So these kinds of bar column charts are great for this kind of categorical data. And then I'll just make one last subtle point is that these are technically called column charts, but you'll hear people call them bar charts all the time. They're really just interchangeable depending on how you wanna show the bars.
Рекомендации по теме