Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Why is my linkaxes(handle.axes,'x') working ok, and my linkaxes((handle.axes,'y') working wrong?!!!!

Subject: Why is my linkaxes(handle.axes,'x') working ok, and my linkaxes((handle.axes,'y') working wrong?!!!!

From: Camille Couzi

Date: 23 Aug, 2010 20:52:04

Message: 1 of 4

Hi!
I have three subplots:
- sub1: where I display a matrix in an imagesc,
- sub2: which displays a line corresponding the place where I have cliked on the imagesc (vertical profile),
- sub3: same thing but for a horizontal profile.

sub1 and sub2 are linked 'y' (for vertical profile), and sub1 and sub3 are linked 'x' (for horizontal profile).
When I make a zoom and pan on the sub3 (x linked with sub1), that work ok, but when I make the same zoom and pan on the sub2 (which is 'x' linked with sub1), then as I move sub1 "up", sub3 moves down!!!!
What is happening?!! I can't understand...

Thanks a lot in advance for your help!!!

Camille.

Subject: Why is my linkaxes(handle.axes,'x') working ok, and my linkaxes((handle.axes,'y') working wrong?!!!!

From: Bruno Luong

Date: 24 Aug, 2010 05:46:08

Message: 2 of 4

"Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <i4un1k$6pk$1@fred.mathworks.com>...
> Hi!
> I have three subplots:
> - sub1: where I display a matrix in an imagesc,
> - sub2: which displays a line corresponding the place where I have cliked on the imagesc (vertical profile),
> - sub3: same thing but for a horizontal profile.
>
> sub1 and sub2 are linked 'y' (for vertical profile), and sub1 and sub3 are linked 'x' (for horizontal profile).
> When I make a zoom and pan on the sub3 (x linked with sub1), that work ok, but when I make the same zoom and pan on the sub2 (which is 'x' linked with sub1), then as I move sub1 "up", sub3 moves down!!!!
> What is happening?!! I can't understand...

I guess the reason is the image always has its vertical axis pointing *downward* and the normal plot has vertical axis pointing *upward*.

Check out the property 'YDir' of the image axes. You might want to either
1. reverse the Y axis of the plot
2. re-reverse the Y axis of the image (you might want to flip the image as well so as it appears rightly)

Bruno

Subject: Why is my linkaxes(handle.axes,'x') working ok, and my linkaxes((handle.axes,'y') working wrong?!!!!

From: Camille Couzi

Date: 24 Aug, 2010 13:33:19

Message: 3 of 4

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <i4vmb0$cbr$1@fred.mathworks.com>...
> "Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <i4un1k$6pk$1@fred.mathworks.com>...
> > Hi!
> > I have three subplots:
> > - sub1: where I display a matrix in an imagesc,
> > - sub2: which displays a line corresponding the place where I have cliked on the imagesc (vertical profile),
> > - sub3: same thing but for a horizontal profile.
> >
> > sub1 and sub2 are linked 'y' (for vertical profile), and sub1 and sub3 are linked 'x' (for horizontal profile).
> > When I make a zoom and pan on the sub3 (x linked with sub1), that work ok, but when I make the same zoom and pan on the sub2 (which is 'x' linked with sub1), then as I move sub1 "up", sub3 moves down!!!!
> > What is happening?!! I can't understand...
>
> I guess the reason is the image always has its vertical axis pointing *downward* and the normal plot has vertical axis pointing *upward*.
>
> Check out the property 'YDir' of the image axes. You might want to either
> 1. reverse the Y axis of the plot
> 2. re-reverse the Y axis of the image (you might want to flip the image as well so as it appears rightly)
>
> Bruno


Hi Bruno!!!
Thanks for your suggestion, that was it! In fact, making
get(gca,'YDir'), I got: reverse!!!!! At no moment I feixed that property, but then I saw this sentence in the imagesc help page:
"By default, imagesc plots the y-axis from lowest to highest value, top to bottom. To reverse this, type set(gca,'YDir','normal'). This will reverse both the y-axis and the image."
I hadn't seen that.
Problem solved! now my zoom and pan i working!

Can I ask you another question please? My subplot1 (imagesc of matrix) is linked 'y' with my sub2 (the profile). When I zoom and pan on the imagesc, that works ok, ie I can't go over the x and y limits, thanks to that nice property of imagesc:
"You cannot interactively pan or zoom outside the x-limits or y-limits of an image."
The problem is that if I pan or zoom on my sub2 (the profile, made with line function), then I can go over those limits, and I don't want to do that!
So two solutions:
- How can I set a similar property "You cannot interactively pan or zoom outside the x-limits or y-limits of a plot made with line" for my sub2?
- or: how can I directly forbid zoom and pan on the sub2?

Thanks a lot for your help, Bruno

Saludos desde Chile!
Camille.

Subject: Why is my linkaxes(handle.axes,'x') working ok, and my linkaxes((handle.axes,'y') working wrong?!!!!

From: Bruno Luong

Date: 24 Aug, 2010 20:26:05

Message: 4 of 4

"Camille Couzi" <camillecouzi@yahoo.fr> wrote in message <i50hmv$p9v$1@fred.mathworks.com>...

> - How can I set a similar property "You cannot interactively pan or zoom outside the x-limits or y-limits of a plot made with line" for my sub2?

Camille,
One way is to intercept the 'ActionPostCallback' of zoom and pan objects, then clip the axis as you wish. Here is a simple example:
 
function testclipzoom

fig = figure(1);
clf;
plot(rand(1,10));
hzoom = zoom(fig);
hpan = pan(fig);
set([hzoom hpan], 'ActionPostCallback', {@clipzoom gca})

end % testclipzoom

function clipzoom(obj,event_obj, haxes)
limits = axis(haxes);
limits = max(limits, [-Inf -Inf 0 Inf]);
limits = min(limits, [+Inf +Inf +Inf 1]);
try
    axis(haxes, limits);
end
end % clipzoom

Hope it helps,

Bruno

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us