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.

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.
----------------------------------------------------------------------
clf
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'});

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?

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

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:

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.

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');
% DO NOT USE FUNCTION 'LINE' HERE
hAxes(1) = gca;
set(hAxes(1),'YColor','b','Box','on');
hAxes(2) = axes('Parent',get(hAxes(1),'Parent'),'Position',get(hAxes(1),'Position'),'YColor','r');
hLine(2) = plot(x2,y2,'r');
set(hAxes(2),'Xlim',get(hAxes(1),'Xlim'),'YAxisLocation','right','Color','none','XTickLabel',[],'Layer','top');
if nargin >= 5
xlabel(hAxes(1),Labels{1},'Color','k');
ylabel(hAxes(1),Labels{2},'Color','b');
ylabel(hAxes(2),Labels{3},'Color','r');
end
if nargin >= 6
if(length(Range(:))==2)
set(hAxes,'Xlim',Range);
else
set(hAxes,'Xlim',Range(1,:));
set(hAxes(1),'Ylim',Range(2,:));
set(hAxes(2),'Ylim',Range(3,:));
end
end
if nargin ==7, legend(hLine,Legends{:}); end;

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!