Plot X vs Y, but with two y-axes for different units

I want to make a time series plot of an estimation error. So time (X) will be on the x-axis and the error (Y) on the y-axis. On the y-axis to the left I want the units of the absolute error (Y), and then I want another y-axis to the right which display the error as a percentage (lets say Y/100). How can I make this work? I guess there is a simple answer! I have tried ployy(x1,y1,x2,y2), but this is not really what I want as I only really got one x and one y - I just want to show the y-range with other numbers to the right... Thanks!

답변 (1개)

Mischa Kim
Mischa Kim 2014년 1월 31일
편집: Mischa Kim 2014년 1월 31일
How about plotyy(x,y,x,y/100)? Of, course you can work with scaling such that you can see both plots reasonably well. In this case you might just want to adjust the labels using something like
set(get(AX(1),'Ylabel'),'String','y')
set(get(AX(2),'Ylabel'),'String','y/100')
where you get AX as an output from the plot command.

댓글 수: 4

The problem with plotyy is that is creates two lines with different color and matching color on the two y-axes. I basically only got one line, I just want to show a different unit for it on the right y-axis..:/
Mischa Kim
Mischa Kim 2014년 1월 31일
편집: Mischa Kim 2014년 1월 31일
I see. Try
figure
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
[AX,H1,H2] = plotyy(x,y1,x,y1/100,'plot');
set(get(AX(1),'Ylabel'),'String','Signal')
set(get(AX(2),'Ylabel'),'String','Signal/100')
set(H1,'LineStyle','--','Color','r')
set(H2,'LineStyle','none','Color','r')
set(AX,{'ycolor'},{'b';'b'}) % ...and to adjust the axis color
Thank you so much for the answer, but I got it to work with this script! http://www.mathworks.com/matlabcentral/fileexchange/7426-plot2axes
That's good to hear. Did the answer solve your problem though? For all the other users with similar questions.

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

카테고리

도움말 센터File Exchange에서 Two y-axis에 대해 자세히 알아보기

질문:

2014년 1월 31일

댓글:

2014년 1월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by