필터 지우기
필터 지우기

Help with a double plot

조회 수: 12 (최근 30일)
aurc89
aurc89 2014년 9월 19일
답변: Guillaume 2014년 9월 19일
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

채택된 답변

Guillaume
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);

추가 답변 (2개)

Mischa Kim
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)
  댓글 수: 1
aurc89
aurc89 2014년 9월 19일
편집: aurc89 2014년 9월 19일
Thanks! There's still a problem: If I want to visualize the plot only between two values of x, let's say between 2 and 5, I use the command
axis([2 5 min max])
where min and max are two values that I set, and this doesn't matter; the problem is along x, because only the function y1 is zoomed between 2 and 5 !

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


Image Analyst
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]);

카테고리

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