image thumbnail

MATLAB Plot Gallery - Line Plot 2D (2)



24 Feb 2012 (Updated )

Create a line plot with legend


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
plot(dates, values)

% Use dateticks for the x axis

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

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

Contact us