1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Python for Finance

Connected

Exercise

Adding a legend

A legend can be useful when plotting multiple datasets to identify which plot is associated with a specific dataset. To add a legend, you can use the label argument. To display the legend on the plot, you can use the function plt.legend().

matplotlib.pyplot is imported as plt and lists stock_A and stock_B are available in your workspace.

Instructions

100 XP
  • Plot histograms for stock_A and stock_B and add labels to each plot ('Stock A' and 'Stock B').
  • Display the legend and the plot.