Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

Specify Legend Descriptions During Line Creation

This example shows how to plot multiple lines and specify the associated legend labels during the plotting command.

Plot three sine curves. For each line, set the DisplayName property.

x = linspace(0,2*pi,100);
y1 = sin(x);
plot(x,y1,'DisplayName','sin(x)');
hold on

y2 = sin(x) + pi/2;
plot(x,y2,'DisplayName','sin(x) + \pi/2');

y3 = sin(x) + pi;
plot(x,y3,'DisplayName','sin(x) + \pi');
hold off

Create the legend. The legend uses the DisplayName property for the labels.

legend('show')

See Also

| |

Was this topic helpful?