getting the axis position correctly
    16 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    dk
      
 el 20 de Abr. de 2011
  
    
    
    
    
    Editada: Yujendra Mitikiri
 el 23 de Oct. de 2021
            I can get the position of the axis easily
figure,plot([0 1], [0 1])
axis equal
AxesHandle=findobj(gcf,'Type','axes');
get(AxesHandle,'Position')
However when I modify the axis limits the axis position does not update.
axis tight
get(AxesHandle,'Position')
still gives me the same answer. How do I get the correct axis position in the second case?
0 comentarios
Respuesta aceptada
  Matt Fig
      
      
 el 20 de Abr. de 2011
        What changes is the tightinset property and plotboxaspectratio.
figure,plot([0 1], [0 1])
axis equal
AxesHandle=findobj(gcf,'Type','axes');
pt1 = get(AxesHandle,{'Position','tightinset','PlotBoxAspectRatio'});
pt1{:}
axis tight
pt2 = get(AxesHandle,{'Position','tightinset','PlotBoxAspectRatio'});
pt2{:}
4 comentarios
  Matt Fig
      
      
 el 20 de Abr. de 2011
				All you are doing here is moving the figure around. Of course this doesn't change the axes properties! Why would you think that moving the figure around would change the axes properties?
Also, you can use GCA to get the axes handle, just like GCF gets the figure handle...
  Matt Fig
      
      
 el 20 de Abr. de 2011
				If you want to get the distance between the edge of the figure and the axis plot area, you need to stop using normalized units and switch to pixels. Then you will see a change.....
figure,plot([0 1], [0 1])
set(gcf,'position', [104 468 1831 420])
axis equal
axis tight
set(gca,'units','pix')
pt1 = get(gca,{'Position','tightinset'}); % [left bottom right top]
set(gca,'units','norm')
pt1{:}
input('Hit return to continue...');
set(gcf,'position', [104 468 793 420])
set(gca,'units','pix')
pt2 = get(gca,{'Position','tightinset'});
set(gca,'units','norm')
pt2{:}
Más respuestas (2)
  Kelly Kearney
      
 el 20 de Abr. de 2011
        I wrote a little function that analyzes the aspect ratios and calculates the plotted axis region:
Should return exactly what you're looking for.
2 comentarios
  Yujendra Mitikiri
 el 23 de Oct. de 2021
				
      Editada: Yujendra Mitikiri
 el 23 de Oct. de 2021
  
			Thank you! This is exactly what I needed, in order to add annotations after making "axis equal."
  Paulo Silva
      
 el 20 de Abr. de 2011
        The position remains the same, don't believe me? go to Tools and press Edit Plot, now click on the axis :)
One thing that do change is the:
xlim
Ver también
Categorías
				Más información sobre Axis Labels en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



