Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Do I Annotate Charts in MATLAB?

I've got a MATLAB script that is called every half hour to build a chart that is placed on my webpage:

load ~/emailAnalysis/results.txt
temp = results(:,3)-1238370000;
h=plot(temp,results(:,1))
xlim([0,max(temp)-1])
ylim([0 max(results(:,1))])
set(gca,'XTick',[1:86400*7:(86400*max(temp))+1])
set(gca,'XTickLabel',[1:1:100])
set(gca,'XGrid','on')
title('Size of inbox over time')
xlabel('Time (Weeks)')
ylabel('Emails')
set(h,'LineWidth',2)
print -djpeg /www/home/joseph/inboxlongterm.jpeg
exit

I'd like to be able to annotate the chart with the occasional text comment (for example, some text centered on a particular x,y coordinate saying "On holiday" or similar).

I had a bit of a Google and didn't get very far at all. Any ideas?

like image 639
Joe Avatar asked Dec 30 '22 15:12

Joe


2 Answers

To add text to a figure at coordinates x,y, use the command

text(x,y,'string')

If you want the text centred on x,y, try:

h = text(x,y,'string')
set(h,'HorizontalAlignment','center')

You can also add arrows or lines to connect the text to a point on a graph using the annotation function.

like image 137
Sam Roberts Avatar answered Jan 01 '23 04:01

Sam Roberts


Looks like MATLAB allows programmatic annotations with the annotation() function.

alt text http://www.mathworks.com/access/helpdesk/help/techdoc/ref/annotationex1.gif

like image 28
Jon W Avatar answered Jan 01 '23 03:01

Jon W