add arrowtext outside the figure

6 次查看(过去 30 天)
评论: Dave B ,2021-10-14
I want to add an arrow with a text outside of my figure plot, in the left side outeside of the y axis, The annotation command gives errors for using negative limits.
I need my annotation to be in the negative section of the figure: a vertical arrow with the text 'y' under the arrow:
annotation('textarrow',[-2 -2],[2.5 3],'String','y')
so my problem is how to define y and x values in order to be able to write left outside of the figure

回答(1 个)

Dave B
Dave B 2021-10-13
编辑:Dave B 2021-10-13
annotations are defined with respect to the figure, in the units of the figure.
pos = 1×4
0.1300 0.1100 0.7750 0.8150
outerpos = 1×4
0 0 1 1
x = mean([outerpos(1) pos(1)])
x = 0.0650
y = [pos(2) pos(2)+pos(4)]
y = 1×2
0.1100 0.9250
annotation('textarrow',[x x],y,'String','y')
  4 个评论
Dave B
Dave B 2021-10-14
You're correct about the first two values, but not exactly for the last two values. Position values in MATLAB are typically x,y,width,height.
Assuming your axes is directly in a figure, and not in another container (like a panel), and not created with the uiaxes function...
  • The bottom left corner (of the 'inner' position) of the axes is 86.5% horizontally and 11% vertically from the bottom
  • the width of your axes is about 4% of the width of the figure window
  • the height of the axes is 81.5% of the height of the figure window
Here's a labeled diagram (with annotation) of all of those locations...and a few more that might be helpful depending on where exactly you're trying to place your arrow:
annotation('rectangle',[.001 0.001 .998 .998],'Color','m') % simulating figure boundary in online
ax.Position=[0.8651 0.1100 0.0399 0.8150];
annotation('doublearrow',[0 ax.Position(1)],[.5 .5],'Color','r')
annotation('doublearrow',[ax.Position(1)+ax.Position(3) 1],[.5 .5],'Color','r')
annotation('doublearrow',[0 ax.Position(1)],[.5 .5],'Color','r')
annotation('doublearrow',[xm xm],[0 ax.Position(2)],'Color','r')
annotation('doublearrow',[xm xm],[ax.Position(2)+ax.Position(4) 1],'Color','r')
annotation('doublearrow',[0 ax.OuterPosition(1)],[.6 .6],'Color','b')
annotation('doublearrow',[ax.OuterPosition(1)+ax.OuterPosition(3) 1],[.6 .6],'Color','b')


Community Treasure Hunt

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

Start Hunting!

Translated by