Matplotlib.pyplot.legend() in Python
Matplotlib.pyplot.legend() function is a utility given in the Matplotlib library for Python that gives a way to label and differentiate between multiple plots in the same figure
The attribute Loc in legend()
is used to specify the location of the legend. The default value of loc is loc= “best” (upper left). The strings ‘upper left’, ‘upper right’, ‘lower left’, and ‘lower right’ place the legend at the corresponding corner of the axes/figure.
The attribute bbox_to_anchor=(x, y) of the legend() function is used to specify the coordinates of the legend, and the attribute ncol represents the number of columns that the legend has. Its default value is 1.
Matplotlib.pyplot.legend() in Python
A legend is an area describing the elements of the graph. In the Matplotlib library, there’s a function called legend() which is used to place a legend on the axes. In this article, we will learn about the Matplotlib Legends.