Plot two lines with a left y axis and one with a right y axis

조회 수: 1 (최근 30일)
Becca
Becca 2012년 4월 11일
댓글: Chris 2014년 12월 9일
I am trying to plot three lines, A, B, and C. A and B have the same scale and the y-axis is on the left. C has a very different scale and the y-axis needs to be on the left. How do I do this?
This is what I have tried:
I can use plotyy because it only allows 2 plots, one for each axis.
I also tried:
plot(A, features...)
hold all;
plotyy(B,C,features...)
where features are the color, line thickness, etc. This just plotted plotyy on top of the orginal plot but messed up all the features from A and I still could not figure out how to change the features in plotyy.
Thank you!

답변 (2개)

Jan
Jan 2012년 4월 11일
Perhaps something like this:
x = linspace(0,2*pi, 20);
y1 = cat(1, sin(x1), cos(x1));
y2 = x .^ 3;
plotyy(x,y1, x,y2);
If this does not match your needs, use the AXES handles replied by plotyy as 'Parent' property for the next plot or line command.

Walter Roberson
Walter Roberson 2012년 4월 11일
h = plotyy(A, features, C, features);
hold(h(1),'all');
plot(h(1), B, features);
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 4월 11일
Note: this is the same solution as using the Parent property. Passing an axes as the first parameter to plot is the same as using that axes as a 'Parent' parameter.

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

카테고리

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