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:
https://app.dataquest.io/m/147/improving-plot-aesthetics/4/visualizing-the-gender-gap

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 https://matplotlib.org/3.2.1/api/_as_gen/matplotlib.pyplot.plot.html?highlight=plot#matplotlib.pyplot.plot.

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.

Thanks.

1 Like

Hi @jdavis,

The use of label argument is taught in this mission screen:
https://app.dataquest.io/m/143/multiple-plots/10/adding-a-legend

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:

Legend

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')

Best,
Sahil