# Documentation

### This is machine translation

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

라이선스가 부여된 사용자만 번역 문서를 볼 수 있습니다. 번역 문서를 보려면 로그인하십시오.

## Add Title, Axis Labels, and Legend to Graph

This example shows how to add a title, axis labels and a legend to a graph using the title, xlabel, ylabel and legend functions. By default, these functions add the text to the current axes. The current axes is typically the last axes created or the last axes clicked with the mouse.

### Create Simple Line Plot

Define x as 100 linearly spaced values between and . Define y1 and y2 as sine and cosine values of x. Create a line plot of both sets of data.

x = linspace(-2*pi,2*pi,100); y1 = sin(x); y2 = cos(x); figure plot(x,y1,x,y2) 

Add a title to the graph using the title function. To display Greek symbols in a title, use TeX markup. Use the TeX markup, \pi, to display the Greek symbol .

title('Graph of Sine and Cosine Between -2\pi and 2\pi') 

Add axis labels to the graph using the xlabel and ylabel functions.

xlabel('-2\pi < x < 2\pi') % x-axis label ylabel('sine and cosine values') % y-axis label 

Add a legend to the graph identifying each data set using the legend function. Specify legend descriptions in the order that you plot the lines.

legend('y = sin(x)','y = cos(x)') 

### Specify Legend Location

Specify the location of the legend on the graph by setting its location using one of the eight cardinal or intercardinal directions. Display the legend at the bottom left corner of the axes by specifying the location as 'southwest'.

legend('y = sin(x)','y = cos(x)','Location','southwest') 

To display the legend outside the axes, append outside to any of the directions, for example, 'southwestoutside'.