How do I make a contour?
4 次查看(过去 30 天)
显示 更早的评论
data = readtable('kriging_branin_20');
krin = readtable('LHS_branin_20.xlsx');
ux1 = unique(data.x1);
nx1 = length(ux1);
X1 = reshape(data.x1, [], nx1);
X2 = reshape(data.x2, [], nx1);
Y = reshape(data.Y, [], nx1);
K = reshape(data.Kriging, [], nx1);
kerr = Y - K;
figure
contourf(X1, X2, abs(kerr), 20)
hold on
scatter3(krin.x1, krin.x2, krin.LHS, 50, 'r', 'filled')
hold off
colormap turbo
xlabel('x1')
ylabel('x2')
title('Sample(n=20)')
colorbar
caxis([0 1])
It is well made in the branin file. However, it is not well made in the rosenbrock file.
Please modify my code. And I want to make contour softer like a Sample_contour picture.
Thank you.
2 个评论
SALAH ALRABEEI
2021-6-16
It depends on your data, but you can play with the intensity level instead of 20 ( increase/decrease).
回答(1 个)
Shivam Lahoti
2024-2-21
Hi 민제 강,
To achieve smoother contours in your plot, you can interpolate the kerr onto a finer grid using interp2. Create a denser mesh with meshgrid and use spline interpolation to obtain the new kerr values. Then, plot the interpolated data with contourf for a smoother appearance. However, be cautious: interpolation can introduce artifacts that may not reflect the actual data distribution.
Kindly refer to the following MATLAB answers, they discuss some other solutions in similar context:
I hope it was helpful.
Regards,
Shivam.
1 个评论
John D'Errico
2024-2-21
This is a well-intentioned answer to this moderately old question, that sadly, never got a timely answer. However, I think your answer misunderstands some facts.
For each surface, the user has provided two sets of points. First is a 20 point scattered set of data. And then they already used kriging to generate a second set of points that lie on a grid. Kriging is itself an interpolation method, one that can be used for cattered data interpolation. As well, kriging can be used to extrapolate scattered data (though it will do so poorly, as will any such method when used for extrapolation.) So if they wanted a finer grid, they could simply have used kriging on the original set to interpolate onto a finer grid!
There is no need to use an interpolation tool to interpolate that grid. In fact, that itself is an arguably bad idea, since interp2 will itself introduce interpolation artifacts. You don't want to interpolate already interpolated data if you have a choice. Just do a finer interpolation in the first place.
As well, you cannot use interp2 to interpolate scattered data (though I think you recognize that.) It would only apply to the already interpolated kriging data.
Anyway, the problem that seems to be vexing @민제 강 is that the Rosenbrock data was not originally interpolated using kriging over the entire domain of the scattered sample. As you can see, there is some white space on the edge of that plot. And interp2 will extrapolate at best only poorly anyway. Since there were only 2 data points outside of the domain, asking interp2 to intelligently extrapolate there is far beyond its capabilities. It would surely introduce major artifacts there.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!