How do I create a single line plot (just one line) with two differently scaled y-axes?
조회 수: 7 (최근 30일)
이전 댓글 표시
I'm looking to create just one single line on a plot with two differently scaled y-axes--the data I need to plot is linearly converted from one value to another, so the shape of the resulting lines is identical. plotyy produces two different lines (which I don't want). Is there an easy way to do this?
댓글 수: 0
답변 (3개)
TastyPastry
2015년 11월 4일
You can use plotyy() to plot two lines on top of each other so you only see one line. If the colors need to be the same, you can adjust them.
x = 1:100;
y = 1:100;
y1 = 101:200;
plotyy(x,y,x,y1);
Star Strider
2015년 11월 4일
편집: Star Strider
2015년 11월 4일
I would set 'Visible','off' for the second line. You can do that with its handle (that you have to request as an output).
Example:
TC = 5:35;
TF = 1.8*TC + 32;
x = 1:length(TC);
figure(1)
[hax,hline1,hline2] = plotyy(x,TC, x,TF);
set(hline2, 'Visible','off')
댓글 수: 0
Kelly Kearney
2015년 11월 4일
편집: Kelly Kearney
2015년 11월 5일
A second option would be to layer two axes manually. For example:
x = rand(100,1);
fac = 2.54;
ax(1) = axes('box', 'off');
ax(2) = axes('Position', get(ax(1), 'Position'), 'yaxislocation', 'right', ...
'xaxislocation', 'top', 'box', 'off', 'color', 'none');
hold(ax(1), 'on');
plot(ax(1), x);
ylabel(ax(1), 'Distance (in)');
ylabel(ax(2), 'Distance (cm)');
set(ax(1), 'ylim', [0 1]);
set(ax(2), 'ylim', get(ax(2), 'ylim')*fac);
The axis layering is basically the same thing plotyy does, except that plotyy chooses axis limits and tick intervals designed to align the tick marks on the two opposing axes. My example doesn't do this (which is why you need to set the 'Box' property to 'off' on both axes, or you'll get some spurious tick marks).
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Two y-axis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!