Azzera filtri
Azzera filtri

Plotting trendlines on plot with 2 y-axes using plotyy

2 visualizzazioni (ultimi 30 giorni)
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?

Risposte (1)

dpb
dpb il 3 Mag 2017
Modificato: dpb il 3 Mag 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.
With R2016a, use yyaxis instead <yyaxis>

Categorie

Scopri di più su Two y-axis in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by