No License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

4.6 | 13 ratings Rate this file 6 Downloads (last 30 days) File Size: 2.1 KB File ID: #11178 Version: 1.0




24 May 2006 (Updated )

A plot function much more powerful than plotyy

Editor's Notes:

This file was a File Exchange Pick of the Week

| Watch this File

File Information

When we use matlab function plotyy, it's inconvenient to setup the labels and ranges of the three axes and the legend of the two lines. What's more, plotyy can not be used in some cases, for example,if the target axes is a child of a uipanel. layerplot enables one who has little knowledge about the graphics handle to plot two lines with two y-axis in one figure and easily setup the corresponding axes properties.

MATLAB release MATLAB 6.5 (R13)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (19)
23 May 2011 paolo

paolo (view profile)

Hi. someone could explain me how i do use this function?

I have no idea to use it. An example please.

I don't speak english very well.

Comment only
10 Mar 2011 Rubakumar Sankararaj

01 Mar 2010 Jeff ahrens

Nice simple program. Just what I needed.

14 Feb 2010 Paul

Paul (view profile)


Great Little Programe - i've lost hours of my life playing with plotyy!!!

I have a question though. I'm using the edited version of the code as per Zhipeng Gao (25 May 2006) but i have a problem plotting the x-axis labels.

Here is my code.
plot_dates = X0_TS.dates('01-Jul-1980::01-Jan-2008');

[hAxes,hLine] = layerplot(plot_dates,fts2mat(hprx_reg.MAT5),plot_dates,fts2mat(X0_reg.IPRO),...
{'Date','Excess Hold Period Return','Difference in Belief'},...
[datenum(1980, 07, 01),datenum(2010, 07, 01); -0.2,+0.2; 0,+3],...
{'Excess Hold Period Return','Difference in Belief'});

datetick('x', 10)


X0.TS is a financial time series object which I extract the dates from. I would like to do something like :

x_ticks = [datenum(1980, 07, 01) datenum(1985, 07, 01) datenum(1990, 07, 01) datenum(1995, 07, 01) datenum(2000, 07, 01) datenum(2005, 07, 01) datenum(2010, 07, 01)];

to specify a common date range for both series. My code above works but but not properly. If I include x_ticks in set(hAxes,'XTick',[]) I get multiple labels on the x-axis?

Is there a simply way of doing this?

Many thanks

Comment only
01 Dec 2009 Nathanael Yoder

Nathanael Yoder (view profile)

Has issues with resizing

01 Dec 2009 Nathanael Yoder

Nathanael Yoder (view profile)

25 Aug 2008 Byron Williams

03 Apr 2008 jon e

ps. to make compatible with subplotting two lines need modification.
figure(...) should be commented out
haxes(1) = axes;
should be changed to haxes(1) = gca;

Comment only
03 Apr 2008 jon e

Nice work. One suggestion is to not have this function automatically plot into a new figure.
For instance, let's say you want to use subplot to have 4 figures all with layerplot, as is, this function can't handle it.
an easy modification to make

30 Jun 2007 Ariell Reshef

07 Sep 2006 Francisco Lopes

It's seems to be perfect!!

30 May 2006 Doug Dusini

I think the author did a very nice job of presenting a solution to making nice yyplots. The coding is a bit cumbersome however. One problem I would like to see addressed is the use of common grid spacing in the y axes so that one plot grid can be used for bothe axes.

29 May 2006 Mukhtar Ullah

Nice work. The syntax goes againts the spirit of Matlab. Who can remember to give some arguments in a cell and others in a matrix. Here is the example given in LAYERSPLOT documentation, using proper MATLAB syntax:

[ax,h(1),h(2)] = plotyy(t,y1,t,y2,'plot');
xlabel(ax(1),'Time (t)');
legend(h,'y = sin(t)','y = 100*cos(t)')
axis(ax(1),[0 2*pi -2 2])
axis(ax(2),[0 2*pi -200 200])

Comment only
27 May 2006 kk zz

It's so excellent. I admired the author very much.

26 May 2006 dodo xing

It is very convenient,good idea ,thank you very much!

26 May 2006 zhou xianove

it's good.

Comment only
25 May 2006 Zhipeng Gao

I can't update layerplot at present.So, I'd like to do some modification in the comments. Now see the following:

hLine(1) = plot(x1,y1,'b');
hAxes(1) = gca;
hAxes(2) = axes('Parent',get(hAxes(1),'Parent'),'Position',get(hAxes(1),'Position'),'YColor','r');
hLine(2) = plot(x2,y2,'r');
if nargin >= 5
if nargin >= 6
if nargin ==7, legend(hLine,Legends{:}); end;

Comment only
25 May 2006 James Richard

It's indeed helpful.Thanks!

24 May 2006 Rick Barnes

Replace "hLine(1) = line(x1,y1);" with "hLine(1) = line(x1,y1,'Color','b');"
in case the default color order does not start with blue. Otherwise, neat!

Contact us