How can I plot the same data with two y-axes on the same plot?
古いコメントを表示
I have some error analysis that requires looking at absolute as well as percent error of some data. I toyed around with plotyy but it essentially plots the data twice with each y-axis. Anyone know how to plot the data once with one scale on the left y-axis (absolute error) and another scale on the right (percent error)
Thanks!
1 件のコメント
Geoff Hayes
2014 年 6 月 11 日
編集済み: Geoff Hayes
2014 年 6 月 11 日
Isn't that what plotyy is for? See the first example at http://www.mathworks.com/help/matlab/ref/plotyy.html as it plots "two data sets on one graph using two y-axes".
採用された回答
その他の回答 (3 件)
You probably made a mistake, how are you calling PLOTYY?
doc plotyy
and look at examples, and e.g. the following which works
x = 0:0.01:20;
y1 = 200*exp(-0.05*x).*sin(x);
y2 = 0.8*exp(-0.5*x).*sin(10*x);
figure % new figure
plotyy(x,y1,x,y2);
Ranzige Erdnuss
2020 年 9 月 27 日
編集済み: Ranzige Erdnuss
2020 年 9 月 27 日
Hi
since plotyy is not recommended anymore, I made an similar approch for yyaxis:
ax = gca;
lLim=ax.YAxis(1).Limits;
rLim=lLim*conversionFaktorOrFun;
ax.YAxis(2).Limits=rLim;
ax.YAxis(1).Limits=lLim;
This following more complete script plots the new COVID-19 casee. Once per 100,000 residents on the left y-axis and once the total number on the right y-axis.
plot(dates, incidence, '.');
xlabel('date');
ylabel('daily new cases per 100,000 residents');
yyaxis('right');
plot(dates, incidence*population, '.', 'Color', 'none');
ylabel('total new infections');
ax = gca;
lLim=ax.YAxis(1).Limits;
rLim=lLim*population;
ax.YAxis(2).Limits=rLim;
ax.YAxis(1).Limits=lLim;
1 件のコメント
Star Strider
2020 年 9 月 27 日
Thank you for your contribution.
Also, the original thread used R2014a, one release prior to R2014b, that introduced ‘HG2’, the new (and still current) handle graphics system. The original code will only work for release/version R2014a and those prior to it.
SAFDAR RASOOL
2019 年 3 月 11 日
0 投票
can we plot this double y plot with the simulink scope?
カテゴリ
ヘルプ センター および File Exchange で Two y-axis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

