stackedplot and linear fit

2 ビュー (過去 30 日間)
zakary Surprenant
zakary Surprenant 2020 年 11 月 24 日
編集済み: Adam Danz 2020 年 11 月 24 日
i was just wondering if they was any way i could put a linear fit line and get its data from stackedplot? I am plotting about 60 graphs so using stackedplot makes it really easy but can't find anything in the help section;
This is a part of my graph where TT_Montlymin,max,mean are 432x3 timetable
%This sets them all together (Max,Min,Mean)
tt=synchronize(TT_Monthlymin,TT_MonthlyMax,Monthlymean);
%this plots them all (Max,Min,Mean)
stackedplot(tt)
  2 件のコメント
Rik
Rik 2020 年 11 月 24 日
To create a linear fit, you will need to extract the x and y positions. What did you try?
zakary Surprenant
zakary Surprenant 2020 年 11 月 24 日
So i would have to extract all my data from 60 graphs and then replot them with a graph for each? I was looking into stackedplot because it graphs everything with the same x, as my x-axis is the same through all my graphs.

サインインしてコメントする。

採用された回答

Adam Danz
Adam Danz 2020 年 11 月 24 日
編集済み: Adam Danz 2020 年 11 月 24 日
> 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
% Create stacked plot
x = linspace(0,20,40);
y = x(:).*[1,2,4,8]+(rand(numel(x),4)-.5)*10;
h = stackedplot(x,y, 'o');
% Get slope and intercepts (slope, intercept)
coefs = arrayfun(@(i){polyfit(x,y(:,i),1)},1:size(y,2));
% Add refline
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,
% Create stacked plot (for demo only)
x = linspace(0,20,40);
y = x(:).*[1,2,4,8]+(rand(numel(x),4)-.5)*10;
h = stackedplot(x,y, 'o');
drawnow()
% Get figure handle, stackedplot handle, and axes handles
fig = gcf();
s = findobj(fig,'Type','stackedplot');
ax = flipud(findobj(s.NodeChildren, 'Type','Axes'));
% Loop through each axis, get (x,y) coordinates, compute and plot reg line
% This assumes there's only 1 group of data within each axes.
for i = 1:numel(ax)
x = get(ax(i).Children,'XData');
y = get(ax(i).Children,'YData');
coef = polyfit(x,y,1);
refline(ax(i),coef(1),coef(2))
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by