How to Add Annotations to Matplotlib Charts
Zenva
ACCESS the FULL COURSE here: https://academy.zenva.com/product/data-science-mini-degree/?zva_src=youtube-datascience-md
TRANSCRIPT
In this video, we are going to make our plot look a bit nicer. And then add things like labels on the axes and the title, but before we do that there's one quick thing that I want to mention and that is that there are a couple different ways we can view these plots. So, the two ways is, one of the ways is what I showed was when you run the plot then it will display up in a separate window. That's one of the ways and the other way is you can actually have it displayed in the IPython console. Sometimes it's better if you're working exclusively with IPython, and you just want to see the plot immediately. You don't want a separate window, or anything. So, those are, kind of, the two big ways that we can view these plots. And if you want to go in between them we can change a value in the preferences of Spyder. So, want to head over to Python preferences. And then, this preferences will open up for the Spyder preferences and you want to go to IPython console.
Go to graphics. Then I have mine set to automatic and automatic will create a separate window and will allow us more interactivity with the plots. So, when a window shows up, those buttons at the bottom that you use to navigate around, if you do inline then it'll show up in the IPython console, but you won't be able to use any. There won't be any buttons for you to mess around with. So then, depending on what you want, you can change this backend. And you have to make sure you quit out of Spyder and restart it, basically, for this to work. Okay. So, now that we have this, let's get over to making our chart look a bit better. So, one thing anything we can do, is add a title. So, we can have a 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 can go with this, but we will look, we will just say let's give it a simple title. So, number of fruit sold, 2017. And so, we can run this and see the title. Next thing here, here in the figure that shows up we have the title at the very top here. There're other configuration options as to where do you want to put the title. And if you go back to matplotlib.org and click on the pyplot button and scroll down, there will be a function called title you can mess around with. So we have that nailed and so the other we want to do is, set a title, or an axis label for the y axis. So we can do that. There's another function called ylabel, and that will label the y axis for us. So I can say, number of fruit, and this will be in the millions. So we can run this. And we see that on the left, you see that there is the number of fruit, millions label on the y axis. An ... https://www.youtube.com/watch?v=APgb-g7CRYk
21855994 Bytes