我正在撰写一篇研究论文,希望能从我的数据集中绘制出类似于下面这张图的内容:
基本上,这是一个 Matlab 散点图,其中显示了每个区间的平均值的低通滤波曲线。
我已经在 Google 上搜索了两天,但还没有找到解决方案或示例代码。
Stack Overflow 现在是我的最后一个选择 :)
![enter image description here](https://istack.dev59.com/sSGMm.webp)
我已经在 Google 上搜索了两天,但还没有找到解决方案或示例代码。
Stack Overflow 现在是我的最后一个选择 :)
这是我能想到的最简单的代码。假设您已经将数据存储在x和y向量中。
%adjust bins accordingly, or add a line that calculates them based on range.
bins = -0.5:0.01:0.5;
nBins = length(bins);
for index = 1:(nBins-1)
binVec = (x >= bins(index) & x < bins(index+1));
lowess(index) = mean(y(binvec));
end
%note that bins are shifted by one half step.
plot(x,y,'.',bins+0.005,lowess,'--r');
这个可以进行向量化处理,但并不值得。至少我找到的方法会使它难以阅读,并且效率可能仅有微小提升。
histc
生成适当分辨率的lowess曲线,并在你的密度图上使用hold plot
进行绘制。