Open oldoc63 opened 1 year ago
plt.legend() can also take a keyword argument loc, which will position the legend on the figure.
These are the position values loc
accepts:
Note: If you decide not to set a value for loc
, it will default to choosing the “best” location.
Sometimes, it's easier to label each line as we create it. If we want, we can use the keyword label inside of plt.plot(). If we choose to do this, we don't pass any labels into plt.legend().
The lines plotted represent the temperatures over the past year in three locations: Hyrule (hyrule) Kakariko (kakariko) Gerudo Valley (gerudo)
Create a list of strings containing "Hyrule", "Kakariko", and "Gerudo Valley", and store it in a variable called legend_labels.
Create a legend for the graph by feeding in legend_labels into plt.legend().
Set the legend to be at the lower center of the chart.
When we have multiple lines on a single graph we can label them by using the command plt.legend(). The legend method takes a list with the labels to display.