add arrowtext outside the figure

63 ビュー (過去 30 日間)
mehra
mehra 2021 年 10 月 13 日
コメント済み: Dave B 2021 年 10 月 14 日
Hello
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.
plot(rand(1,10))
pos=get(gca,'Position')
pos = 1×4
0.1300 0.1100 0.7750 0.8150
outerpos=get(gca,'OuterPosition')
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 件のコメント
mehra
mehra 2021 年 10 月 14 日
thanks for your explanation,
In my case the results of pos are like:
pos=get(gca,'Position')
pos =
0.8651 0.1100 0.0399 0.8150
so I guess the first two values are x and y for start point of the figure, and the last two values are x and y for the end point of the figure,right? In order to better calculate the x and y for the arrow I want to know exactly where they come from , (sth/sth in the figure), so 0.8651 is the almost 86percent of the figure in x axis??
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:
ax=gca;
plot(ax,randn(10,1))
xlabel('xlabel')
ylabel('ylabel')
title('title')
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('rectangle',ax.Position,'Color','r','LineWidth',2)
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')
xm=ax.Position(1)+ax.Position(3)/2;
annotation('doublearrow',[xm xm],[0 ax.Position(2)],'Color','r')
annotation('doublearrow',[xm xm],[ax.Position(2)+ax.Position(4) 1],'Color','r')
annotation('rectangle',ax.OuterPosition,'Color','b','LineWidth',2)
annotation('doublearrow',[0 ax.OuterPosition(1)],[.6 .6],'Color','b')
annotation('doublearrow',[ax.OuterPosition(1)+ax.OuterPosition(3) 1],[.6 .6],'Color','b')

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by