Axes Position property seems to be incorrect

3 views (last 30 days)
Bryan Wilson
Bryan Wilson on 7 Oct 2022
Commented: dpb on 7 Oct 2022
I have a chromaticity plot and a few line data series plotted over the plot. I've adjusted the axes to zoom in on a smaller section of the plot.
Something is wrong with the Position(1) and Postion(3) values for the Axes object. As I understand, Position(1) should be the horizontal position of the lower-left axes corner and Position(3) is the width of the axes, normalized between 0 and 1 within the Figure. But my Position(1) is left of the axes and Position(3) is wider than the axes. I'm trying to annotate my data series, but the mixed up Position values are throwing me for a loop.
plotChromaticity
hold on;
a = gca;
% Set axes limits
xlim([0.20,0.55]);
ylim([0.30, 0.8]);
% Set Ticks
a.TickLength = [0.04 0.04];
a.TickDir = 'out';
% Values
xMtics = [a.XLim(1):0.10:a.XLim(2)];
xmtics = [a.XLim(1):0.05:a.XLim(2)];
yMtics = [a.YLim(1):0.10:a.YLim(2)];
ymtics = [a.YLim(1):0.05:a.YLim(2)];
%Set Tick Value Labels
a.XAxis.TickValues= xMtics;
a.XAxis.MinorTick= 'on';
a.XAxis.MinorTickValues= xmtics;
a.YAxis.TickValues= yMtics;
a.YAxis.MinorTick= 'on';
a.YAxis.MinorTickValues= ymtics;
% Plotting data on top of chromaticity
data_x = [0.31, 0.32, 0.34; 0.30, 0.33, 0.29];
data_y = [0.50, 0.54, 0.51; 0.48, 0.50, 0.35];
h1 = plot(data_x(:,1),data_y(:,1),'k-x',data_x(:,2),data_y(:,2),'k:+',data_x(:,3),data_y(:,3),'k--o');
legend(h1,'Mod. Acrylic', 'Thermoplastic','Failed product','FontSize',9,'Location',"Northeast");
% Convert from XY to normalized location for annotations
xnorm = a.Position(3)/(a.XLim(2)-a.XLim(1));
ynorm = a.Position(4)/(a.YLim(2)-a.YLim(1));
arrow_loc_x = a.Position(1) + (data_x(1,:) - a.XLim(1)) .* xnorm;
arrow_loc_x = [arrow_loc_x+0.04; arrow_loc_x];
arrow_loc_y = a.Position(2) + (data_y(1,:) - a.YLim(1)) .* ynorm;
arrow_loc_y = [arrow_loc_y+0.04; arrow_loc_y];
% Try to annotate first point in Thermoplastic data
annotation('textarrow', arrow_loc_x(:,2), arrow_loc_y(:,2),'String',' Not pointing to data :(')
% Plotting the axes "Position" box.
annotation('rectangle',[a.Position(1),a.Position(2),a.Position(3),a.Position(4)]);
annotation('textarrow',[0.85;a.Position(1)+a.Position(3)],[0.65;0.6],'String',"Axes Position box",'HorizontalAlignment','right')
  1 Comment
dpb
dpb on 7 Oct 2022
We can't duplicate because we don't have PlotChromaticity function/script so not really any way to debug...
BUT, if run the code from after that point, then the axes position box does align with the axes over the xlim,ylim positions. Hence, it appears whatever was done inside that function first has left its mark on what was picked up by gca.
From the top w/o the missing script leaves the following for which the axes/positions appear ok. What gca was referring to before, we can't tell.
We'll have to be able to reproduce the whole image to be able to tell what is going on...

Sign in to comment.

Answers (0)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by