plot03.m - Annotations and Greek Letters

x = linspace(0,2*pi,60);     % define 60 x values from 0 to 2 pi
y = sin(x);                  % calculate sin(x)
plot(x,y,'bo')               % plot y vs. x

% set the plot limits on the x and y axes
xlim([-0.2 2*pi+0.2]);
ylim([-1.2, 1.2]);

% label x and y axes and give the plot a title
xlabel('\theta');
ylabel('sin(\theta)');
title('Annotation Example');

% calculate the index of the middle data point
% Use the x and y coordinates of this data point to position a text
% annotation. Then write some randon Greek letters near the bottom of the
% plot (just because I can).
mid = round(length(x)/2);
text(x(mid)+0.1,y(mid),'\leftarrow Here is my favorite data point');
text(0.1,-1,'Some random Greek letters:  \alpha, \theta, \Sigma, \phi, \pi');

Download plot03.m

This example plots sin(x) vs. x using open blue circles and annotates it with some text. A few things to notice about this code:


Monkey Home   |    Prev   |   Next