> i was just wondering if they was any way i could put a linear fit line and get its data from stackedplot?
If you're creating the stackedplot then you alread have the x,y coordinates which you can use to compute the regression lines. To add those lines to the stackedplot you'll need to use undocumented methods since the axis handles are unavailable by default.
Here's a demo
y = x(:).*[1,2,4,8]+(rand(numel(x),4)-.5)*10;
h = stackedplot(x,y, 'o');
coefs = arrayfun(@(i){polyfit(x,y(:,i),1)},1:size(y,2));
ax = flipud(findobj(h.NodeChildren, 'Type','Axes'));
arrayfun(@(i)refline(ax(i),coefs{i}(1),coefs{i}(2)),1:numel(ax))
If you do not have access to the raw data and only have the figure, you can get the x,y coordinates and add reference lines using,
y = x(:).*[1,2,4,8]+(rand(numel(x),4)-.5)*10;
h = stackedplot(x,y, 'o');
s = findobj(fig,'Type','stackedplot');
ax = flipud(findobj(s.NodeChildren, 'Type','Axes'));
x = get(ax(i).Children,'XData');
y = get(ax(i).Children,'YData');
refline(ax(i),coef(1),coef(2))
Best Answer