How to add plots to a plotyy and enlarge the abscissa?
Show older comments
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 ;)
1 Comment
Azzi Abdelmalek
on 28 Oct 2012
I don't see any problem in your code
Answers (2)
Image Analyst
on 28 Oct 2012
Edited: Image Analyst
on 28 Oct 2012
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.
Azzi Abdelmalek
on 28 Oct 2012
Edited: Azzi Abdelmalek
on 28 Oct 2012
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
Azzi Abdelmalek
on 28 Oct 2012
Edited: Azzi Abdelmalek
on 28 Oct 2012
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]);
Olivier
on 29 Oct 2012
Categories
Find more on Two y-axis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!