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!