Matplotlib legend in subplotIn this tutorial, we will learn how Matplotlib can be used to include legends in subplots. The legend can be added after creating the plot using the legend() function. Syntax:The syntax for legend in subplot is: where, loc is used for location. Approaches:Following are the approaches we will use for displaying legend in the subplot in Matplotlib:
Example 1:In this example, we will plot the scatter graph using subplot of log10 and exponential: Output Example 2:In this example, we will plot the scatter graph using subplot of sine and cos: Output Example 3:In this example, we will plot the scatter graph using subplot of (y = x^2) and (y = x^3): Output ConclusionIn this tutorial, we have discussed how to use legend in the subplot of matplotlib graphs using different methods. |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India