How to plot graph with three axsis (an example figure is included )

조회 수: 1 (최근 30일)
Bander
Bander 2014년 7월 1일
댓글: dpb 2014년 7월 4일
Hi
I have three variables and would like to plot them as in the following figure which was produced in Excel.
The Red curve is plot by x,y axis (time vs rho). the blue curve is plotted by x,z axis (N vs rho) the yellow curve is plotted by x,z axis (N vs rho)
Thanks in advance.

답변 (5개)

dpb
dpb 2014년 7월 3일
...not sure what is the mistake I am doing. As you can see in the figure that the legend does not reflect the curves colors.
Don't plot the same stuff multiple times...you've thoroughly confused legend by having multiple lines of the same stuff.
A) Plot the data on the axes desired...
[hax hl1 hl2] = plotyy(rho,time,rho,[avg_n max_n],'semilogy','plot');
B) Then fixup the line handles to the desired properties...
set(hl1,'MarkerFaceColor',[0 0.498039215803146 0],...
'MarkerEdgeColor',[0 0.498039215803146 0],...
'Marker','>',...
'Color',[0 0.498039215803146 0],'MarkerSize',5,'LineWidth',2)
and so on for the two on the RH axis using hl2(1) and hl2(2)
Then legend will have only the three needed lines, not two or three copies of each.
  댓글 수: 1
Bander
Bander 2014년 7월 3일
Thanks for your valuable comment, I have tried the way you said but it f=give me the following error:
??? Undefined function or method 'h12' for input arguments of type 'double'.
Error in ==> plot_RHO_vs_n at 42
set(h12(2),'MarkerFaceColor',[0 0 1],'MarkerEdgeColor',[0 0 1],...
Here is an updated code as you suggestion:
dataRHO=load('RHO_max_k_n_time5.txt');
figure(1)
time=dataRHO(:,end);
rho=dataRHO(:,5);
avg_n=dataRHO(:,3);
max_n=dataRHO(:,2);
hax hl1 hl2] = plotyy(rho,time,rho,[avg_n max_n],'semilogy','plot');
set(hl1,'MarkerFaceColor',[0 0.498039215803146 0],...
'MarkerEdgeColor',[0 0.498039215803146 0],...
'Marker','>',...
'Color',[0 0.498039215803146 0],'MarkerSize',5,'LineWidth',2)
set(hl2(1),'MarkerFaceColor',[1 0 0],'MarkerEdgeColor',[1 0 0],...
'Marker','o',...
'LineStyle','--',...
'Color',[1 0 0],'MarkerSize',6,'LineWidth',2)
set(h12(2),'MarkerFaceColor',[0 0 1],'MarkerEdgeColor',[0 0 1],...
'Marker','square',...
'LineStyle','--','MarkerSize',5,'LineWidth',2)
ylabel(hax12(1),'Safe Window','FontSize',14)
ylabel(hax12(2),'n','FontSize',14)
xlabel('\rho_m','FontSize',14)
legend('Safe Window vs \rho_{m}','n_{avg} vs \rho_m','n_{max} vs \rho_m')
hold off
grid on

댓글을 달려면 로그인하십시오.


Ryan
Ryan 2014년 7월 1일

dpb
dpb 2014년 7월 1일

Bander
Bander 2014년 7월 3일
I have tried plotyy but not sure what is the mistake I am doing. As you can see in the figure that the legend does not reflect the curves colors.
here is the code:
dataRHO=load('RHO_max_k_n_time5.txt');
figure(1)
time=dataRHO(:,end);
rho=dataRHO(:,5);
avg_n=dataRHO(:,3);
max_n=dataRHO(:,2);
[hax12 line1 hline2] = plotyy(rho,time,rho,avg_n,'semilogy','plot')
set(hax12,'NextPlot','add')
plot(hax12(1),rho,time,'MarkerFaceColor',[0 0.498039215803146 0],...
'MarkerEdgeColor',[0 0.498039215803146 0],...
'Marker','>',...
'Color',[0 0.498039215803146 0],'MarkerSize',5,'LineWidth',2)
plot(hax12(2),rho,avg_n,'MarkerFaceColor',[1 0 0],'MarkerEdgeColor',[1 0 0],...
'Marker','o',...
'LineStyle','--',...
'Color',[1 0 0],'MarkerSize',6,'LineWidth',2)
plot(hax12(2),rho,max_n,'MarkerFaceColor',[0 0 1],'MarkerEdgeColor',[0 0 1],...
'Marker','square',...
'LineStyle','--','MarkerSize',5,'LineWidth',2)
ylabel(hax12(1),'Safe Window','FontSize',14)
ylabel(hax12(2),'n','FontSize',14)
xlabel('\rho_m','FontSize',14)
legend('Safe Window vs \rho_{m}','n_{avg} vs \rho_m','n_{max} vs \rho_m')
hold off
grid on

Bander
Bander 2014년 7월 4일
. . . . . . . Any help please.
  댓글 수: 2
Image Analyst
Image Analyst 2014년 7월 4일
편집: Image Analyst 2014년 7월 4일
You've had 4 answers already. Did you overlook them?
dpb
dpb 2014년 7월 4일
The revised one you posted looks ok to me...whatever it was that was the typo that created the error is/would be readily fixable; in fact, it looks like that's precisely what you did to generate the figure.
What, specifically, is wrong with it?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by