Experiment No. 4


What is a Legend in a Chart?

A legend is a small box or label on a chart that explains what different lines, bars, colors, or symbols represent.

Simple Example

Suppose you have a chart showing sales of two products:

    • 🔵 Product A
    • 🟠 Product B

The legend tells the reader:

Legend

    • 🔵 → Product A
    • 🟠 → Product B

Without the legend, it may be difficult to understand what each line or bar represents.

In Python

We use:

For example:

Here, label="Monthly Sales" gives a name to the data, and plt.legend() displays that name on the chart.

plt.legend()
plt.plot(months, sales, label="Monthly Sales")
plt.legend()

Post a Comment