Skip to content

legend

Add a legend to the chart.

legend(label1, label2, ...)
legend({'label1', 'label2'})
legend('off')
legend('Location', 'best')

Adds a legend identifying each plotted series by color/style and label. Labels can be passed individually or as a cell array. Trailing name-value pairs control position and appearance — 'Location' accepts 'north', 'south', 'east', 'west', 'best', 'northeastoutside', etc.

plot(x, y1, x, y2);
legend('Series A', 'Series B', 'Location', 'northeast')
  • colorbar — Add a color-scale legend to the figure.
  • title — Set the title of the current axes.
  • xlabel — Set the x-axis label.