image thumbnail

MATLAB Plot Gallery - Line Plot 2D (2)

by

 

24 Feb 2012 (Updated )

Create a line plot with legend

Line_Plot_2D_2

This is an example of how to create an line plot with legend in MATLAB®.

Read about the plot function in the MATLAB documentation.

For more examples, go to MATLAB Plot Gallery

% Load data for the stock indices
load IndexData dates values series

% Plot the stock index values versus time
figure
plot(dates, values)

% Use dateticks for the x axis
datetick('x')

% Add title and axis labels
xlabel('Date')
ylabel('Index Value')
title('Relative Daily Index Closings')

% Add a legend in the top, left corner
legend(series, 'Location', 'NorthWest')

Contact us