This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Exclude Objects from Graph Legend

This example shows how to plot several lines and create a legend that includes descriptions for a subset of the lines.

Plot four lines and return each chart line object as an output argument from the plot function.

x = linspace(0,5,500);
y1 = exp(0.1*x).*sin(6*x);
p1 = plot(x,y1);

hold on
y2 = exp(0.2*x).*sin(6*x);
p2 = plot(x,y2);

y3 = exp(0.3*x).*sin(6*x);
p3 = plot(x,y3);

y4 = exp(0.4*x).*sin(6*x);
p4 = plot(x,y4);

Create a legend in the lower left corner of the axes. Include descriptions for only the first and last lines in the legend by specifying p1 and p4 as the first input argument.

hold off
legend([p1 p4],'e^{0.1x}sin(6x)','e^{0.4x}sin(6x)','Location','southwest')

See Also

| | |

Was this topic helpful?