Help with a double plot
조회 수: 12 (최근 30일)
이전 댓글 표시
I need to plot two functions, y1 and y2, versus the same axis x. y1 values are very 'distant' from the ones of y2 (eg. y1=[2 4 7 3 5 6], y2=[25000 56000 78000 32000 78000 39000]). Thus, I need to plot y1 and y2 on two different scales but on the same plot, for example y1 between 0 and 10 and y2 between 0 and 100000. A command like:
plot(x,y1,x,y2)
cannot give me that. How can I do? thanks
댓글 수: 0
채택된 답변
Guillaume
2014년 9월 19일
I would use xlim, if you only want to change the limits of the x axis. plotyy creates two axis, so you need to change the limits for both of them.
axs = plotyy(x, y1, x, y2);
xlim(axs(1), [2 5]);
xlim(axs(2), [2 5]);
%or arrayfun(@(ax), xlim(ax, [ 2 5]), axs);
댓글 수: 0
추가 답변 (2개)
Mischa Kim
2014년 9월 19일
편집: Mischa Kim
2014년 9월 19일
Use, plotyy:
x = 1:6;
y1 = [2 4 7 3 5 6]:
y2 = [25000 56000 78000 32000 78000 39000];
plotyy(x,y1,x,y2)
Image Analyst
2014년 9월 19일
That's certainly bizarre. Not sure why the x axis gets so messed up. Here's a workaround:
x = 1:6;
y1 = [2, 4, 7, 3, 5, 6];
y2 = [25000, 56000, 78000, 32000, 78000, 39000];
plotyy(x,y1,x,y2)
% xlim([2,5]); % Produces messed up x axis
% Here's a workaround
xIndexes = x >= 2 & x <= 5; % Find indexes that are in range.
% Plot only those indexes in range, and don't mess with xlim().
plotyy(x(xIndexes),y1(xIndexes),x(xIndexes),y2(xIndexes))
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.1, 1, .5]);
댓글 수: 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!