From the course: Python for Marketing (2019)

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Adding a legend to a plot

Adding a legend to a plot - Python Tutorial

From the course: Python for Marketing (2019)

Adding a legend to a plot

- [Instructor] Legends are incredibly important on plots. If the person reading it does not know what data they're looking at then you will struggle to communicate what you need from them, and what you're trying to convey to them. So, in order to add a legend, it's very easy, it's, you essentially, you have your Maplotlib subplot codes with your plots, and then you're customizing the plot in general, so that's the figures that we're customizing, this part. And to do that, we do fig.legend, and what that will do is it will look into the subplots, and it will pull out clicks and page views, along with our color, and it will pull out a legend. If I run this, you will see how that works. Legend's up here, it's got the data. If we don't do this, then we get nothing, and people don't know what really they're looking at, guess it, but you don't want to leave it to people to guess. There we go, that's how you add legends to plots in a.

Contents