How to plot three different things with different y-directions in current plot?

1 view (last 30 days)
Dear all I am trying to plot three different kinds in one axis of the plot. However, one of the graph has different Ylimit. I would like to have similar plots in excel. In this regard I am not talking about subplot. Below is the code , I developed.
clean
dirOut = 'Graphics\Scatters';
mkdir(dirOut);
prgm = 131;Nyears=60; decile=10;
expr = ['dy = fm_model_' int2str(prgm) '(p, ndata);']; % model to use
Paramlabel = parameters(prgm);
numparam = length(Paramlabel);
ndays = 5;
parray = zeros(Nyears, numparam);
decilevec = zeros(Nyears, 2);
m = 1;
for data_choice=1:Nyears
[dirGraph, RName, Filein, DiaryFile, param_file] = drawer(data_choice,...
prgm);
data = getdata( Filein ); data=data(:);
ndata = length(data);
[p itn] = getparam(param_file, 4, m);
[Dpy, DLy ] = percentile(data,decile);
decilevec(data_choice,1) = DLy;
eval(expr);
dy = stat_moving(dy,ndays);
[Ppy, PLy ] = percentile(dy,decile);
parray(data_choice,:) = p;
decilevec(data_choice,2) = PLy;
end
hold on
h1 = plot(decilevec(:,1), 'k');
h2 = plot(decilevec(:,2), 'r');
h3 = plot(parray(:,2), 'b');
set(h3, 'YDir', 'reverse');
hold off;
While running I got error like this. Error using graph2d.lineseries/set The name 'YDir' is not an accessible property for an instance of class 'lineseries'.
It will be great if anyone knows how to solve this problem. Sooner response will be appreciative and cooperative, Thanks in advance.
Sincerely Mahesh

Accepted Answer

Neha Talnikar
Neha Talnikar on 21 Jul 2014
The command h = plot() returns the column vector of lineseries handles which does not have the property ‘YDir’. The axes object has this property. You should be looking to set this property for an axes object instead.
I would suggest using ‘plotyyy’ for doing this. ‘plotyyy’ lets you have 3 y-axes. The plot looks less cluttered and is easier to manipulate.
This is available on File Exchange and following is the link: http://www.mathworks.com/matlabcentral/fileexchange/1017-plotyyy
Once you use the ‘plotyyy’ to create the figure, then you can change the ‘YDir’ property of the specific axes by using ‘set’ function:
ax = plotyyy(x,y1,x,y2,x,y3);
set(ax(3),'YDir','reverse');

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!