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:
plot 2 axes y in the same figure

Subject: plot 2 axes y in the same figure

From: Jose

Date: 3 Feb, 2010 16:34:23

Message: 1 of 4

Hello everyone, I want to plot two curves in the same figure, with two different
axes y, the first axe start in 0(top) to 1250(bottom), and the second axe y go to 0 (bottom) to 4 (top).


x1=0:4/(227-1):4;
y1=0:226;
 plot(x1,snrscore,y1,epsnscore)
 set(gca,'YDir','reverse'); % It is necessary for the epsnscore function.

Where snrscore is a vector of size 227, i.e for example a sigmoid function (monotonous crescent), and epsnscore is a vector of size 227, i.e, for example a (1-sigmoid) function (monotonous decrescent).

Some help,

Thnaks in advance.

Jose.

Subject: plot 2 axes y in the same figure

From: ade77

Date: 3 Feb, 2010 16:42:07

Message: 2 of 4

"Jose " <jose.l.vega@gmail.com> wrote in message <hkc8if$hp1$1@fred.mathworks.com>...
> Hello everyone, I want to plot two curves in the same figure, with two different
> axes y, the first axe start in 0(top) to 1250(bottom), and the second axe y go to 0 (bottom) to 4 (top).
>
>
> x1=0:4/(227-1):4;
> y1=0:226;
> plot(x1,snrscore,y1,epsnscore)
> set(gca,'YDir','reverse'); % It is necessary for the epsnscore function.
>
> Where snrscore is a vector of size 227, i.e for example a sigmoid function (monotonous crescent), and epsnscore is a vector of size 227, i.e, for example a (1-sigmoid) function (monotonous decrescent).
>
> Some help,
>
> Thnaks in advance.
>
> Jose.

doc plotyy

Subject: plot 2 axes y in the same figure

From: Paul Mennen

Date: 4 Feb, 2010 07:30:25

Message: 3 of 4

>> "Jose " wrote
>> I want to plot two curves in the same figure, with two different axes y

"ade77 " wrote
> doc plotyy

Many people find the plotyy documentation terse and difficult to understand if you aren't a handle graphics expert. An alternative called plt.m available on the file exchange is more flexible and has a logical well documented parameter structure that doesn't require expertise in the arcane syntax of matlab handle graphics. Running it's demo (demoplt.m) should be sufficient to determine if this function will be to your liking.

~Paul

Subject: plot 2 axes y in the same figure

From: Jose

Date: 5 Feb, 2010 15:47:03

Message: 4 of 4

Thanks to everyone, I understood the plotyy function:

xmin=-6
xmax=6
x=xmin:0.1:xmax;

y1=1./(1+exp(-x)); % sigmoid function (blue solid line)
y2=y1; % green dashed line

[ax,h1,h2]=plotyy(x,y1,x,y2)
set(ax(2),'YDir','reverse') % change the direction of the right-y axe
set(h2,'LineStyle',':') % change the style of the second curve

set(ax(1),'xlim',[xmin xmax]) % change x-axes limits of the first plot
set(ax(2),'xlim',[xmin xmax]) % change x-axes limits of the second plot
% It is a trick to avoid the overlapping of the two tick labels, ax(1) and ax(2).


set(ax(1), 'YColor', [0 0 0]) % change color (black) of the right-y axe
set(ax(2), 'YColor', [0 0 0]) % change color (black) of the left-y axe

I hope it can help.


"Paul Mennen" <nospam@mennen.org> wrote in message <hkdt2h$8nj$1@fred.mathworks.com>...
> >> "Jose " wrote
> >> I want to plot two curves in the same figure, with two different axes y
>
> "ade77 " wrote
> > doc plotyy
>
> Many people find the plotyy documentation terse and difficult to understand if you aren't a handle graphics expert. An alternative called plt.m available on the file exchange is more flexible and has a logical well documented parameter structure that doesn't require expertise in the arcane syntax of matlab handle graphics. Running it's demo (demoplt.m) should be sufficient to determine if this function will be to your liking.
>
> ~Paul

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