From the course: Data Analysis with Python and Pandas

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Chart legends and gridlines

Chart legends and gridlines

- [Instructor] All right, and so now let's take a look at our chart legend. Our legend is often very important in a chart because it communicates to users what our lines represent. There are going to be some times when we might want to remove the legend altogether. Perhaps we're going to create a legend by hand in a tool like PowerPoint. These legends in Matplotlib can be very finicky, especially when we're only working with the Matplotlib API via Pandas. But by default, Pandas is going to try to place your legend in the best spot, so it's going to look for regions of your chart where there's a lot of white space in the hopes that we won't be obscuring any of our data. But if we look at this chart here, it's very hard to find a spot where there's enough white space inside our chart where our legend would not cover up our data. And so if you ever run into this, one easy way to take care of this would just be to say legend=False, and we no longer have a legend. Unfortunately, your…

Contents