Borrar filtros
Borrar filtros

Plotting trendlines on plot with 2 y-axes using plotyy

1 visualización (últimos 30 días)
mcl1993
mcl1993 el 3 de Mayo de 2017
Editada: dpb el 3 de Mayo de 2017
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?

Respuestas (1)

dpb
dpb el 3 de Mayo de 2017
Editada: dpb el 3 de Mayo de 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>

Categorías

Más información sobre Two y-axis en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by