help with using plotyy
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jingxin
am 31 Mär. 2015
Kommentiert: Jingxin
am 2 Apr. 2015
I want to plot four sets of data using plotyy. The four sets are two sets of experimental data and the other two are predicted (calculated) values. Therefore, they would have different sizes. Ex, the experimental data for x and y are 13 points, while for predicted value, I have x=0:100:1. Therefore I can not use the plotyy with matrix method. Could anyone help with this? Thanks in advance.
0 Kommentare
Akzeptierte Antwort
Kelly Kearney
am 31 Mär. 2015
So you want one predicted/experimental pair on one axis, and another predicted/experimental pair on the other axis? If so, plot both predicted sets with plotyy, save the handles to the resulting axes, and then plot the experimental datasets:
x{1} = linspace(0,10,13);
y{1} = rand(1,13);
x{2} = linspace(0,10,100);
y{2} = rand(1,100);
x{3} = linspace(0,10,13);
y{3} = rand(1,13) * 100;
x{4} = linspace(0,10,100);
y{4} = rand(1,100) * 100;
[hax, hln(1,1), hln(2,1)] = plotyy(x{1}, y{1}, x{3},y{3});
hold(hax(1), 'on');
hold(hax(2), 'on');
hln(1,2) = plot(hax(1), x{2}, y{2}, 'o');
hln(2,2) = plot(hax(2), x{4}, y{4}, 'x');
Weitere Antworten (1)
the cyclist
am 31 Mär. 2015
plotyy is really only needed if your different y values have very different scales (e.g. number of employees and total revenue over time). Because you are doing a fit, I am guessing that your y values are about the same scale.
Therefore, I think you really only need the ability to plot two lines on the same plot (even if they different lengths.) There are several ways to accomplish that. Here is one simple example.
% Pretend data with 13 points
data_x = rand(1,13);
data_y = rand(1,13);
% Pretend fit with 100 points [NOT AN ACTUAL FIT. JUST MADE UP!]
fit_x = linspace(0,1);
fit_y = 0.5*ones(size(fit_x)) + 0.1*fit_x.^2;
% Figure with both data and "fit"
figure
hold on
plot(data_x,data_y,'.')
plot(fit_x,fit_y)
3 Kommentare
Chad Greene
am 31 Mär. 2015
I agree with the cyclist. If you're comparing predicted values to measured values, you should not use plotyy. If the y scales are so vastly different between predicted and measured values, that's probably an issue worth depicting clearly, letting the viewer directly compare the different values. Use
plot(x,predicted_y,'k-')
hold on
plot(x,measured_y,'ro')
Siehe auch
Kategorien
Mehr zu Two y-axis 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!