How to add plots to a plotyy and enlarge the abscissa?

Hi everybody,
I'd like to add some different plots in a main plotyy window and enlarge the abscissa. For now, here's what I've got (the second part after the -.-.-.- line is false):
figure;
hold on
[AX,H1,H2] = PLOTYY(sorted_x,moy10,sorted_x,iTurb10);
set(get(AX(1),'Ylabel'),'String','(m/s)','color','k')
set(get(AX(2),'Ylabel'),'String','(%)','color','k')
set(AX(1), 'YColor', 'r')
set(AX(2), 'YColor', 'b')
set(H1,'linestyle','-.','marker','o','color','r','linewidth',2);
set(H2,'linestyle','--','marker','^','color','b','linewidth',2);
-.-.-.-
hold(AX(1));
plot(AX(1),129,9.4,'k+','linewidth',3);
hold(AX(2));
plot(AX(2),0:200,0.3,'m:','linewidth',3);
plot(AX(2),0:200,0.15,'m:','linewidth',3);
hold off
I manage to modify every single thing I want in the main plotyy window but I don't manage to add those three plots after...
Actually, the width of the abscissa is currently (approximatively) 10 to 110 and I'd it to be from 0 to 200. Plus, I'd like to link the first plot to the left y-axis (related with moy10) and the two other plots to the right y-axis (iTurb10).
It that all possible?
If you have any answers, I'd like to hear it! Thank you ;)

Answers (2)

Use xlim() to set the range of the x axis:
xlim([0 200]);
There is a corresponding ylim() function if you'd also like to set the range of the y axis.
Your code is correct, you have just to set xlim
The second part of your code:
hold(AX(1));
plot(129,9.4,'k+','linewidth',3,'parent',AX(1));
hold(AX(2));
plot(0:200,0.3,'m:','linewidth',3,'parent',AX(2));
plot(0:200,0.15,'m:','linewidth',3,'parent',AX(2));
set(AX,'xlim',[0 200])
hold off

3 Comments

Ok then here's my current code
% figure;
hold on
[AX,H1,H2] = PLOTYY(sorted_x,moy10,sorted_x,iTurb10);
set(get(AX(1),'Ylabel'),'String','Vitesse moyenne (m/s)','color','k')
set(get(AX(2),'Ylabel'),'String','Intensité de la turbulence (en %)','color','k')
set(AX(1), 'YColor', 'r')
set(AX(2), 'YColor', 'b')
set(H1,'linestyle','-.','marker','o','color','r','linewidth',2);
set(H2,'linestyle','--','marker','^','color','b','linewidth',2);
hold(AX(1));
plot(129,9.4,'k+','linewidth',3,'parent',AX(1));
hold(AX(2));
plot(0:200,0.3,'m:','linewidth',3,'parent',AX(2));
plot(0:200,0.15,'m:','linewidth',3,'parent',AX(2));
set(AX,'xlim',[0 200])
hold off
end
(without "if true" and "end" - I don't know how to use the balise code ^^)
The problem is the following when I execute it :
??? Error using ==> hold at 69 Unknown command option.
Error in ==> mycode at 118 hold(AX(2));
Actually, when I comment one of the first hold(AX(1)); and his linked plot, it does work, but it is absolutely not in the window. I have to search for it far away with the hand-tool. How can I just rescale the figure to make these plots fitting into the figure itself? And how can I plot all the plots linked each its axis? I remind you : the first plot with the left y-axis and the two others with the right one.
Thanks in advance :) I kind of lost ^^'
You said error at 69, how can I know what is in 69? anyway, now, your problem is with rescaling Y axis
for the first axis, you have to find min(y) and max(y) (of both plots)
set(AX(1),'ylim',[miny1 maxy1])
for the second axis , do the same for the three plots, find miny2 and maxy2
set(AX(2),'ylim',[miny2 maxy2]);
Thank you.
The error at the line 69 is in the hold function of matlab, it doesn't concern my code.
Anyway, what you gave me works, but there are no numbers on the axis outside the previous plotyy window... And yet, there is that error that doesn't allow me the plot the four plots all together.
I don't have much time left to finish this code, so anyway thank you very much for helping me and if you have an idea to fix the two problems, I'll be very happy ^^
Bye

Sign in to comment.

Categories

Asked:

on 28 Oct 2012

Community Treasure Hunt

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

Start Hunting!