Annotation position driving me mad!! changing the position values won't work...

3 次查看(过去 30 天)
I have a position for my annotation on an axis, but it keeps being placed in another location and changing the position values doesn't seem to work!! can someone help me?
code:
axes5 = axes('Parent',gcf,'FontSize',16,...
'Position',[0.727083333333333 0.10948905109489 0.227777777777778 0.352189781021897]);
hold(axes5,'on');
h = annotation(gcf,'textbox',...
[0.887210317460318 0.0666889185580782 0.0746944444444443 0.148331108144192],...
'LineStyle','none',...
'FitBoxToText','off','position',[0.652488095238095 0.153471295060081 0.0746944444444444 0.148331108144192],'String',...
{['mixture of strings and mat2str functions used here to display fit coefficients, r^2 etc.']});
cheers! Michael

回答(2 个)

Image Analyst
Image Analyst 2015-11-6
Your 'Units' property is probably wrong - not 'normalized'. Try specifying normalized units
axes(....... , 'Units', 'normalized', ................);

Mike Garrity
Mike Garrity 2015-11-6
What did you expect this to do? And how does that differ from what it is doing?
Here's a simplified version of your code:
p1 = [0.727083333333333 0.10948905109489 ...
0.227777777777778 0.352189781021897];
axes5 = axes('Parent',gcf,'FontSize',16,...
'Position',p1);
p2 = [0.887210317460318 0.0666889185580782 ...
0.0746944444444443 0.148331108144192];
p3 = [0.652488095238095 0.153471295060081 ...
0.0746944444444444 0.148331108144192];
h = annotation(gcf,'textbox',p2,...
'LineStyle','none',...
'FitBoxToText','off','Position',p3, ...
'String',['mixture of strings and mat2str functions' ...
' used here to display fit coefficients, r^2 etc.']);
We can label the X coordinates like so:
annotation('textarrow',[p1(1) p1(1)],[.70 .3],'String',sprintf('X = %g',p1(1)))
annotation('textarrow',[p2(1) p2(1)],[.75 .3],'String',sprintf('X = %g',p2(1)))
annotation('textarrow',[p3(1) p3(1)],[.80 .3],'String',sprintf('X = %g',p3(1)))
And we get this:
As you can see, the left side of the axes is at p1(1), which is what you specified. The left side of the text box is at p3(1). This one's a little tricky because you gave the annotation command two different positions. The first one (p2) was passed in as the 3rd argument. The second one (p3) was passed in using "PV-pairs". In this case, the second one wins. If you had specified the Position several times in the PV-pairs, then the last one would have one.
You can do the same sort of operation for the other 3 components of the Position, and I think that you'll find that it is doing what you asked it to do.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by