Plotting trendlines on plot with 2 y-axes using plotyy
7 views (last 30 days)
Show older comments
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 Comments
Answers (1)
dpb
on 3 May 2017
Edited: dpb
on 3 May 2017
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 Comments
See Also
Categories
Find more on Two y-axis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!