2D plot help
1 view (last 30 days)
Show older comments
[EDIT: 20110623 10:21 CDT - reformat - WDR]
Hi everybody. I have been given the following code,
L=[0 10 20 30 40 50 60 70 80 90 100];
Op=[0.492 0.498 0.503 0.509 0.514 0.52 0.524 0.528 0.532 0.533 0.53];
ASE=[0.0499 0.0509 0.0517 0.0528 0.0539 0.0553 0.057 0.0594 0.0629 0.0694 0.0826];
SNR=[19.72 19.57 19.46 19.28 19.07 18.81 18.39 17.78 16.92 15.36 12.83];
x=[0:0.01:100];
y1=interp1(L,Op,x,'spline');
y2=interp1(L,ASE,x,'spline');
y3=interp1(L,SNR,x,'spline');
figure(1)
n=4;
p=polyfit(x,y1,n)
yi=polyval(p,x);
plot(x,yi,'-');
[M,h1,h2]=plotyy(x,yi,x,y2);
set(gca,'linewidth',2);
box off
set(h1,'linewidth',2);
set(h1,'linestyle','-');
set(h2,'linewidth',2);
xlabel('Forward pump beam (% of total pump energy)','FontSize',13);
ylabel(M(1),'Output Seedbeam Power (W)','FontSize',13);
ylabel(M(2),'ASE Power with output seed beam(W)','FontSize',13);
set(M(1),'ytick',[0.49:0.01:0.55],'ylim',[0.49 0.55]);
set(M(2),'ytick',[0.04:0.01:0.1],'linewidth',2)
hh=legend('Output seedbeam ','ASE');
set(hh,'FontSize',13)
I have used the plotyy function to plot yi (which is the best fit curve of y1) as well as y2 against x. I need to add ASE and Op to my plot as well (versus x) to essentially have 2 sets of data points, and 2 curves on the same plot. I have tried adding them to the plotyy function to no avail and am currently searching around for another way to do it.
Any help would be appreciated.
Thanks!
0 Comments
Answers (1)
Arturo Moncada-Torres
on 23 Jun 2011
You could overlap plots using hold. For example:
figure();
hold('on');
plot(1:10, 'b*');
plot(10:-1:1, 'ro');
hold('off');
However, the problem here is that the x scale for your plotted data does not match with the scale for ASE or Op, so even if you put them together the visualization would not be correct. Try fixing that and then include the hold part in your code.
2 Comments
Arturo Moncada-Torres
on 23 Jun 2011
Since you got an answer to your original question, could you please mark this question as answered and ask this in a new thread? This is to keep the forum as clean as possible. I will continue helping you there ;) !
See Also
Categories
Find more on Log Plots 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!