Four data sets on one plot
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hey guys, I have four data sets that I am trying to put on on plot. My code is as follows,
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);
[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)
hold on
[M,h1,h2]=plotyy(L,Op,L,ASE);
set(h1,'linestyle','o');
set(h2,'linestyle','x');
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)
hold off
My problem is that ASE is not being properly plotted against L in the right y-axis, Op plots just fine. When I try to plot ASE the axis scaling gets thrown off even though I explicitly state that I want it to remain identical to the initial plot. Just to recap, I need Op and yi plotted using the left y-axis, and I need ASE and y2 plotted against the right y-axis, without the scale getting ruined in the process. I feel like I am so close to finishing this assignment. Thanks for your help!
Derek
0 Kommentare
Antworten (2)
Fangjun Jiang
am 24 Jun. 2011
I am not sure what is the problem. If you want to adjust the scale, can't you just use the axis() function?
0 Kommentare
Arturo Moncada-Torres
am 24 Jun. 2011
I think in a raw way, this is what you want, am I right?
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');
n=4;
p=polyfit(x,y1,n);
yi=polyval(p,x);
figure();
hold('on');
plot(L,Op,'ro');
plot(L, ASE, 'rx');
plot(x, yi, 'b');
plot(x, y2, 'g');
hold('off');
EDIT Notice how the new plot has the two original lines (in blue and green) and the points ("o" and "x") in red. The x axis goes from 0 to 100 and the y axis is the same for all of the plots.
Run it and let me know.
3 Kommentare
Arturo Moncada-Torres
am 24 Jun. 2011
Yikes, see the edit, I forgot to delete one line of code to produce only the plot you want.
Siehe auch
Kategorien
Mehr zu Axis Labels finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!