2
votes

I've got a figure with two subplots being displayed. I want to get the axis position of each plot so I am using the figure's children information:

 subplot(211)
 % Plot stuff here
 ...
 subplot(212)
 % Plot stuff here 
 ...

 % Get Axes Position information
 f =gcf;
 % Bottom Plot Axis
 disp(f.Children(2).Position)
 % Top Plot Axis
 disp(f.Children(4).Position)

The console displays:

 Bottom plot:
     0.1300    0.1100    0.7750    0.3412

 Top plot:
     0.1300    0.5838    0.7750    0.3412

This seems correct given all else. When I run the plot to generate the figure and then inspect the axes' information via 'Show Plot Tools and Dock Figure->Inspector: matlab.graphics.axis.Axes' option the width value for each axis's position is not 0.7750. The other position values are as listed but the width is different for both the top and bottom plots. The top becomes [0.13 0.5838 0.682 0.341] and the bottom becomes [0.13 0.11 0.67 0.341].

Does anyone know why this is and how to get the "real" position values and not the incorrect displayed/printed ones?

Useful info: MATLAB R2014b

EDIT UPDATE: Here is a MWE that produces the behavior.

clear all; close all; clc; 
figure; 

subplot(211)
hold on

x1 = [ -1 -0.998 -0.996 -0.994 -0.992];
y = [0.000324249267578125 -0.000370025634765625 -3.4332275390625e-005 -0.000186920166015625 -0.000110626220703125];
plot(x1, y, '-', 'MarkerSize', 10) 

set(gca, 'FontName', 'Interstate-Light', 'FontSize', 7)
set(gca, 'XTickLabel', [])
set(gca, 'XLabel', [])
grid on
ylabel('Frequency Error (Hz)', 'FontName', 'Interstate-Bold')
legend({'FE'}, 'Location', 'NorthEastOutside', 'FontName', 'Interstate-Light', 'Box', 'off')

subplot(212)
hold on
x1 = [ -1 -0.998 -0.996 -0.994 -0.992];
y = [-0.010614013299346 -0.0417663566768169 0.0235949698835611 -0.0502893067896366 0.0316442884504795];
plot(x1, y, '-', 'MarkerSize', 10) 

% Overide X-axis ticks to align with data
XTick = unique(x1);

grid on;
xlabel('Time (s)', 'FontName', 'Interstate-Bold')
ylabel('Frequency Error (Hz)', 'FontName', 'Interstate-Bold')
set(gca, 'FontName', 'Interstate-Light', 'FontSize', 7)
legend({'RFE'}, 'Location', 'NorthEastOutside', 'FontName', 'Interstate-Light', 'Box', 'off')

% Get figure object
f = gcf;
% Set fontsize to 16 for readability in final pdf
set(findall(f, '-property','FontSize'),'FontSize',16)
f.PaperUnits = 'inches';
f.PaperPosition = [0 0 20 14];
f.PaperPositionMode = 'manual'; 

% Get axis position info
disp('Second plot:')
disp(f.Children(2).Position)
disp('First Plot:')
disp(f.Children(4).Position)
1
I cannot reproduce this issue with the code and steps provided.excaza
Doesn't docking the figure change the geometry of the window? Or that shouldn't be an issue?Andras Deak
@AndrasDeak the default units of the axes generated by subplot are Normalized and should not change with the geometry of the window.excaza
@excaza emphasis on the "should not"?:)Andras Deak
@AndrasDeak if you can show that this happens, feel free.excaza

1 Answers

2
votes

I'm working with R2012b and I've been able to reproduce the problem and also (almost) been able to understand what's happening.

I do not know if it is also applicable to more "recent" versin of MatLab.

The problem seems related to the default configuration of the window Show Plot Tools and Dock Figure

enter image description here

With this configuration, actually the position of the two axes (read in the Property editor are different with respect to the "original ones:

original pos ax 1=  [0.1300    0.5838    0.7750    0.3412]
new pos ax1=[0.1300    0.629     0.7750    0.268 ]

Nevertheless, if you minimize the Property editor tab and look at the Position of the two axes, they are restored to the "original" one values.

You can, the "slide up" the tab and the position still remain the "original onne.

I'do not know if this is actually an answer to you question; what I can say is that the right position position are the "original" ones.

It could be a sort of bug in the visualization in the default configuratin od the Show Plot Tools and Dock Figure window.

Hope this helps.

enter image description here enter image description here

enter image description here