Tuesday, 5 September 2023

How Legends Make Your Plots More Informative?

 

Legend provide information about the various elements in the plot. Legends make the plot more informative to the end-user.

 

For example, take a look at the below diagram without legend.




From the above diagram, it is very difficult or impossible to the end user, what information the plot is telling to us.

 

With legend

 


As you observe above diagram with legend, it is very clear that

a.   Red color line represent the relationship between x and its square

b.   Green color line represent the relationship between x and its cube.

 

plot_legend.py

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(1, 10)
y1 = x**2
y2 = x**3

plt.plot(x, y1, label="y = x^2", color='r')
plt.plot(x, y2, label="y = x^3", color='g')

plt.legend()
plt.show()

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment