Help with a double plot
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
aurc89
am 19 Sep. 2014
Beantwortet: Guillaume
am 19 Sep. 2014
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 Kommentare
Akzeptierte Antwort
Guillaume
am 19 Sep. 2014
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 Kommentare
Weitere Antworten (2)
Mischa Kim
am 19 Sep. 2014
Bearbeitet: Mischa Kim
am 19 Sep. 2014
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 Kommentar
Image Analyst
am 19 Sep. 2014
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 Kommentare
Siehe auch
Kategorien
Mehr zu Axis Labels finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!