image thumbnail

MATLAB Plot Gallery - Adding Text to Plots (1)

by

 

23 Feb 2012 (Updated )

Add text to a plot

Add_Text_to_Plot_1

This is an example of how to add text to a plot in MATLAB®.

Read about the text function in the MATLAB documentation.

For more examples, go to MATLAB Plot Gallery

% Load the points for creating a spline curve
load splineData points x y

% Plot the points for the spline curve
figure
plot(points(:,1),points(:,2),':ok')
hold on

% Plot the spline curve
plot(x, y, 'LineWidth', 2)
axis([.5 7 -.8 1.8])

% Add a title and axis labels
title('The Convex-Hull Property')
xlabel('x')
ylabel('y')

% Label points 3, 4, & 5 of the spline curve
xt = points(3,1) - 0.05;
yt = points(3,2) - 0.1;
text(xt, yt, 'Point 3')

xt = points(4,1) - 0.05;
yt = points(4,2) + 0.1;
text(xt, yt, 'Point 4')

xt = points(5,1) + 0.15;
yt = points(5,2) - 0.05;
text(6.1,.5, 'Point 5')

Contact us