problem with ginput when having 2 axes in the same figure

I have a figure containing 2 axes, the first axes ax(1) contains a line object, it is a spectrum y = y(k). The x-axis here is inverse. The second axes ax(2) ('color','none') is just overlaid and does not contain any graphic object. It's x-axis on top is the (not reversed) wavelength.(The x-limits of the second are adjusted, so that both x-axis have the appropriate positions, e.g. k=0.1 --> x=10 stacked) However, this is to my knowledge the only way in MATLAB to achieve a second reverse x-axis for the same curve in a loglog diagram.
My problem: I want to get two x-coordinates in ax(1) by [x,~]=ginput(2); To be sure it is the right axes I use set(gcf,'CurrentAxes',ax(1))
Now, when I look at the resulting x values, they do come from ax(2), not from ax(1). I haven't any clue why this doesn't work.
Any help is much appreciated.

3 Kommentare

a code snippet, how the plot is produced
figure
ax(1)=axes;
line(k,y)
set(gca,'xscale','log','yscale','log')
xlim1=get(gca,'xlim');
xlim2=1./fliplr(xlim1);
ax(2) = axes('Position',get(ax(1),'Position'),'XAxisLocation','Top', ...
'Color','none','XDir','reverse', ...
'xscale','log','yscale','log','xlim',xlim2);
Try setting HitTest off for the second axis.
Thanks Walter. With
set(ax(2),'HitTest','off')
it works. But why this behaviour?
In the help page for "ginput" is stated that "ginput raises crosshairs in the current axes". Has this to do with the stack of the two axes?
Thanks.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Wendy Fullam
Wendy Fullam am 11 Jan. 2013
Answered by Walter:
"Try setting HitTest off for the second axis."
set(ax(2),'HitTest','off')

Weitere Antworten (0)

Kategorien

Mehr zu Data Exploration finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by