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?