### Tags: 01180y1, allx, axis, code, consistent, followingclearclose, limits, matlab, plotyy, programming, x1y4, xlim

# xlim problem in plotyy

On Programmer » Matlab

5,705 words with 9 Comments; publish: Sun, 18 May 2008 21:08:00 GMT; (200156.25, « »)

Hi,

I have xlim problem in plotyy.

The limits of x axis are not consistent.

The code is following:

clear;close all;

x = 0:1:180;

y1 =x+1;

y4 =-2.*x-1;

plot(x,y1,'-');

[AX,H1,H2] = plotyy(x,y1,x,y4,'plot');

set(get(AX(1),'Ylabel'),'String','Left Y-axis')

set(get(AX(2),'Ylabel'),'String','Right Y-axis')

xlabel('Zero to 20 \musec.')

title('Labeling plotyy')

set(H1,'LineStyle','--')

set(H2,'LineStyle',':')

xlim([0 200]);

Results show two x limits: one is 0~180, the other one is 0~200 in

figure.

If I change the command "plot(x,y1,'-');" into "plot(x,y1,'-');xlim([0

200]);"

The results are also the same.

Why?

Thank you in advance.

Mike

*http://matlab.questionfor.info/q_matlab_65615.html*

All Comments

Leave a comment...

- 9 Comments
- On Mar 3, 10:12 am, "Mike" <a....matlab.questionfor.info.yam.com> wrote:
> Hi,

> I have xlim problem in plotyy.

> The limits of x axis are not consistent.

> The code is following:

> clear;close all;

> x = 0:1:180;

> y1 =x+1;

> y4 =-2.*x-1;

> plot(x,y1,'-');

> [AX,H1,H2] = plotyy(x,y1,x,y4,'plot');

> set(get(AX(1),'Ylabel'),'String','Left Y-axis')

> set(get(AX(2),'Ylabel'),'String','Right Y-axis')

> xlabel('Zero to 20 \musec.')

> title('Labeling plotyy')

> set(H1,'LineStyle','--')

> set(H2,'LineStyle',':')

> xlim([0 200]);

> Results show two x limits: one is 0~180, the other one is 0~200 in

> figure.

> If I change the command "plot(x,y1,'-');" into "plot(x,y1,'-');xlim([0

> 200]);"

> The results are also the same.

> Why?

> Thank you in advance.

> Mike

I add "xlim(AX(2),[0 200]); " at the last statement. Inconsistent x

limits also occur.

#1; Sun, 18 May 2008 21:10:00 GMT

- On Mar 3, 10:12 am, "Mike" <a....matlab.questionfor.info.yam.com> wrote:
- On Mar 3, 10:20 am, "Mike" <a....matlab.questionfor.info.yam.com> wrote:
> On Mar 3, 10:12 am, "Mike" <a....matlab.questionfor.info.yam.com> wrote:

>

>

>

>

>

>

>

>

> I add "xlim(AX(2),[0 200]); " at the last statement. Inconsistent x

> limits also occur.- Hide quoted text -

> - Show quoted text -

please tell me.

#2; Sun, 18 May 2008 21:11:00 GMT

- On Mar 3, 10:20 am, "Mike" <a....matlab.questionfor.info.yam.com> wrote:
- Mike:
<SNIP axial pain...

> xlim([0 200]);

must read

set(AX,'xlim',[0,200]);

us

#3; Sun, 18 May 2008 21:12:00 GMT

- Mike:
- On Mar 5, 9:30 am, us <u....matlab.questionfor.info.neurol.unizh.ch> wrote:
> Mike:

> <SNIP axial pain...

>

> must read

> set(AX,'xlim',[0,200]);

> us

thank you very much, us. It works.

But why?

#4; Sun, 18 May 2008 21:13:00 GMT

- On Mar 5, 9:30 am, us <u....matlab.questionfor.info.neurol.unizh.ch> wrote:
- is it possible to plot more than two signals with their y axis into
one figure? How?

thanks

#5; Sun, 18 May 2008 21:14:00 GMT

- is it possible to plot more than two signals with their y axis into
- On Mar 5, 2:39 pm, witt <tauchv....matlab.questionfor.info.centrum.cz> wrote:
> is it possible to plot more than two signals with their y axis into

> one figure? How?

> thanks

plotyy can do this.

#6; Sun, 18 May 2008 21:15:00 GMT

- On Mar 5, 2:39 pm, witt <tauchv....matlab.questionfor.info.centrum.cz> wrote:
- Mike wrote:
>

> On Mar 5, 2:39 pm, witt <tauchv....matlab.questionfor.info.centrum.cz> wrote:

> into

> plotyy can do this.

>

I tried to achieve it, but without success.

help plotyy and doc plotyy show it only for two signals

I would like to plot more than two with their y axis.

Can you give me an example?

thx

#7; Sun, 18 May 2008 21:16:00 GMT

- Mike wrote:
- > I tried to achieve it, but without success.
> help plotyy and doc plotyy show it only for two signals

> I would like to plot more than two with their y axis.

> Can you give me an example?

> thx

If you want to plot many traces, "plt" is a good

alternative to "plotyy". (Just search for "plt"

on the file exchange). You can put as many traces as

you want on the left or right axes, and the documentation

is much more extensive (and many usage examples).

Just type "help plt" for a short help or "plt help"

for a complete description. Also try "demoplt.m" in the

plt\demo folder which runs thru all the example programs

to give you an idea of what you can do with plt.

(I just added a example that does waterfall plots.)

Let me know if it works for you, or if not let me

know what you didn't like.

~Paul

#8; Sun, 18 May 2008 21:17:00 GMT

- > I tried to achieve it, but without success.
- Paul Mennen wrote:
>

> If you want to plot many traces, "plt" is a good

> alternative to "plotyy". (Just search for "plt"

> on the file exchange). You can put as many traces as

> you want on the left or right axes, and the documentation

> is much more extensive (and many usage examples).

> Just type "help plt" for a short help or "plt help"

> for a complete description. Also try "demoplt.m" in the

> plt\demo folder which runs thru all the example programs

> to give you an idea of what you can do with plt.

> (I just added a example that does waterfall plots.)

> Let me know if it works for you, or if not let me

> know what you didn't like.

> ~Paul

nice work ...

... but, I cant create using plt more than two y axes. There is only

one left and one right axe. I want to create for every signal special

y axe.

other functios...

when I analyze real signals, I often use distance of 2 points (eg.

right and left mouse button)

witt

#9; Sun, 18 May 2008 21:18:00 GMT

- Paul Mennen wrote: