Plotting trendlines on plot with 2 y-axes using plotyy
2 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Two y-axis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!