Add multiline text annotation to graph with different colors
12 views (last 30 days)
Show older comments
I am generating a plot of the calibration for 3 different sensors. I need to annotate it with the calibration constants, and I would like to color code the annotations.
Right now I am using a loop to create the annotation as one char array so I don't have to align each annotation individually:
for i=1:3
labels(i,:)=['Probe ',num2str(i),' : ',num2str(cal_const(i),'%0.1f')];
end
I then add a title to my annotation block:
labels=strvcat('Calibration Constants','(in mm/volt)',labels)
And add it to my plot:
text(-1.35,-10,labels);
I would like to color rows 2-4 of 'labels' to correspond to the plotted calibration data, but it seems I would need to use individual text(...) commands to achieve this, which then puts me back in the situation of having to individually align 4 separate text annotations.
I am sure there are better ways to accomplish these annotations, what should I be doing instead?
Thanks, Jake
0 Comments
Answers (1)
Image Analyst
on 15 Mar 2014
Edited: Image Analyst
on 15 Mar 2014
That is most likely something you'll find only on Yair's site: http://undocumentedmatlab.com/?s=text+colors Hoever his solution might be more complicated to calling text() 3 times (I don't know). What's the big deal with aligning? You just use the same x value in all three calls to text(). No big deal.
3 Comments
Image Analyst
on 15 Mar 2014
I don't know. You'd have to try and see. Maybe you can change the units so that it's normalized to the size of the axes control instead of using the x,y ranges of the data that got plotted.
KAE
on 17 Jan 2017
I have the same problem: want the y spacing to remain constant when I resize the figure.
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!