As the question states, I would like to obtain the screen coordinates of a given point on a plot. I am not interested in getting the plot-dependent coordinates of a point selected by the user (I would use ginput
for that like in this answer).
Instead, I would like to return the coordinates in the [0,1] units of a given point on a plot (e.g. I create a figure with figure('units','normalized','outerposition',[0 0 1 1])
).
The reason I want to do this is an extension of this answer, which I reproduce the code hereunder. I would like to determine posSmall{1}
such that the location of the axes matches certain coordinates in the graph. For instance, I would like to put the first small axis such that its bottom left corner is at (40,-8) on the graph on the left.
%# sample data
x = 1:100;
left = randn(100,1);
right = cumsum(rand(100,1)-0.5);
%# build axes positions
hBig = [subplot(121) subplot(122)]; %# create subplots
posBig = get(hBig, 'Position'); %# record their positions
delete(hBig) %# delete them
posSmall{1} = [0.275 0.63 0.16 0.24];
posSmall{2} = [0.717 0.63 0.16 0.24];
%# create axes (big/small)
hAxB(1) = axes('Position',posBig{1});
hAxB(2) = axes('Position',posBig{2});
hAxS(1) = axes('Position',posSmall{1});
hAxS(2) = axes('Position',posSmall{2});
%# plot
figure('units','normalized','outerposition',[0 0 1 1]);
plot(hAxB(1), x, left, 'b');
plot(hAxB(2), x, right, 'b');
plot(hAxS(1), x, left, 'r');
plot(hAxS(2), x, right, 'r');
%# set axes properties
set(hAxB, 'XLim',[1 100], 'YLim',[-10 10]);
set(hAxS , 'Color','none', 'XAxisLocation','top', 'YAxisLocation','right');
For this to work, I would need to determine the position of the point (40,-8) in the first graph and set posSmall{1}
accordingly.
Thanks in advance.