help with using plotyy

5 visualizzazioni (ultimi 30 giorni)
Jingxin
Jingxin il 31 Mar 2015
Commentato: Jingxin il 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.

Risposta accettata

Kelly Kearney
Kelly Kearney il 31 Mar 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');
  1 Commento
Jingxin
Jingxin il 2 Apr 2015
Thanks! This works perfectly! Cheers!

Accedi per commentare.

Più risposte (1)

the cyclist
the cyclist il 31 Mar 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 Commenti
Chad Greene
Chad Greene il 31 Mar 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')
Jingxin
Jingxin il 2 Apr 2015
yeah...I kinda have to do that way.

Accedi per commentare.

Categorie

Scopri di più su Two y-axis in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by