How to annotate graphs in MATLAB?

I have a MATLAB script that is called every half hour to build a diagram posted on my web page:

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 would like to be able to annotate the diagram with a random text comment (for example, some text oriented to a specific x, y coordinate saying "On vacation" or the like).

I had a bit of Google, and I didn’t get very far. Any ideas?

+4
source share
3 answers

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

 text(x,y,'string') 

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

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

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

+4
source
+4
source

You can also use the text function

 text(x,y,'string') 

where x, y are the coordinates. If you want to output text with tex characters, you can combine the texlabel function with a text function

 text(x,y, texlabel('lambda12^(3/2)/pi - pi*delta^(2/3)')) 
+2
source

All Articles