In this article, we will see how to put the legend outside the plot.
Let’s discuss some concepts :
Matplotlib:Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack. It was introduced by John Hunter in the year 2002.
Legend: 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. The attribute Loc in legend() is used to specify the location of the legend. The default value of loc is loc= “best” (upper left).
Put the legend outside the plot
As, we can see that the above figure legends overlapped on the graph i.e; incomplete information. To solve this problem we need to place the legend outside the plot.
The syntax to set the legend outside is as given below:
Matplotlib set legend upper-left outside the plot.
Please Login to comment...