help with using plotyy

5 ビュー (過去 30 日間)
Jingxin
Jingxin 2015 年 3 月 31 日
コメント済み: Jingxin 2015 年 4 月 2 日
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.

採用された回答

Kelly Kearney
Kelly Kearney 2015 年 3 月 31 日
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 件のコメント
Jingxin
Jingxin 2015 年 4 月 2 日
Thanks! This works perfectly! Cheers!

サインインしてコメントする。

その他の回答 (1 件)

the cyclist
the cyclist 2015 年 3 月 31 日
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 件のコメント
Chad Greene
Chad Greene 2015 年 3 月 31 日
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 2015 年 4 月 2 日
yeah...I kinda have to do that way.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTwo y-axis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by