add arrowtext outside the figure
    22 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
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
0 Kommentare
Antworten (1)
  Dave B
    
 am 13 Okt. 2021
        
      Bearbeitet: Dave B
    
 am 13 Okt. 2021
  
      annotations are defined with respect to the figure, in the units of the figure. 
plot(rand(1,10))
pos=get(gca,'Position')
outerpos=get(gca,'OuterPosition')
x = mean([outerpos(1) pos(1)])
y = [pos(2) pos(2)+pos(4)]
annotation('textarrow',[x x],y,'String','y')
4 Kommentare
  Dave B
    
 am 14 Okt. 2021
				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')
Siehe auch
Kategorien
				Mehr zu Printing and Saving finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




