필터 지우기
필터 지우기

Plotting trendlines on plot with 2 y-axes using plotyy

조회 수: 1 (최근 30일)
mcl1993
mcl1993 2017년 5월 3일
편집: dpb 2017년 5월 3일
I am using plotyy to plot two data sets on the same plot. The data have very different scales so it is good to use two scales. I am trying to plot a straight line through the data that is plotted using the second axis (the purple circle data). However, when I plot the trendline, it is not appearing it the right place as it is using the left axis to scale and not the right axis which is the scale the data I am fitting corresponds to. This is the dotted line almost across the x-axis. How do I plot the trendline using the second axis?

답변 (1개)

dpb
dpb 2017년 5월 3일
편집: dpb 2017년 5월 3일
hAx=plotyy(.....); % plot your two axes, keeping the handles to same
...
hold(hAx(2),'on') % set HOLD status for RH axes
plot(hAx(2),x2,yhat2) % and add the trendline on same...
Above presumes you've computed the fit and evaluated it as yhat2 from the appropriate x,y data for the RH axes. Of course, only need two points from some min/max range for a straight line.
With R2016a, use yyaxis instead <yyaxis>

카테고리

Help CenterFile Exchange에서 Two y-axis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by