Plot label feature not previewed in use before used in solution?

Use of the matplotlib.pyplot.plot option of a label was not previewed in any step, in this mission or any prior mission, I think, before it was used in the model solution of mission 147 step 4.

Screen Link:

I. eventually, understood the matplotlib.pyplot.plot was supposed to be used in this step’s task, based on step 2 of mission 147, Introduction To The Data–finding how to create a label for the plots was not stated. To find that out required multiple searches, through my takeaways, through internet search engines, and finally, through the matplotlib documentation, ending up at the page

On that page, I had to browse through four screens of documentation to find information about **kwargs, which then had a code sample showing how to label a line in a matplotlib plot.

Please consider making how to use the label option of the matplotlib.pyplot.plot method more explicit in the lessons or takeaways.


1 Like

Hi @jdavis,

The use of label argument is taught in this mission screen:

To help remind us which year each line corresponds to, we can add a legend that links each color to the year the line is representing. Here’s what a legend for the lines in the last screen could look like:


When we generate each line chart, we need to specify the text label we want each color linked to. The pyplot.plot() function contains a label parameter, which we use to set the year value:

plt.plot(unrate[0:12]['MONTH'], unrate[0:12]['VALUE'], c='red', label='1948')

plt.plot(unrate[12:24]['MONTH'], unrate[12:24]['VALUE'], c='blue', label='1949')

We can create the legend using pyplot.legend and specify its location using the loc parameter:

plt.legend(loc='upper left')