Methods for smoothing contour lines

11 次查看(过去 30 天)
I have a database P with columns X, Y and Z (file above):
N = 150; % Number Of Points Desired
xv = linspace(min(P(:,1)), max(P(:,1)), N);
yv = linspace(min(P(:,2)), max(P(:,2)), N);
[X,Y] = ndgrid(xv, yv);
Z = griddata(P(:,1), P(:,2), P(:,3), X, Y);
contourf(X, Y, Z, 35)
Zi = interp2(P(:,1), P(:,2), P(:,3), X, Y) ;
With the code above, I get the following plot:
How to make contour lines neater and smoother?

采纳的回答

Star Strider
Star Strider 2022-10-20
编辑:Star Strider 2022-10-20
I dislike going to external sites.
Increasing ‘N’ would be the option I would use, initially experimenting with 250 and perhaps 500 or greater, depending on the available memory and the result provided. That should increase the resolution of the vectors, and therefore the resolution of the matrices derived from them.
EDIT — (20 Oct 2022 at 15:45)
Using the supplied data —
LD = load(websave('P','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1163343/P.mat'));
P = LD.P;
N = 500; % Number Of Points Desired
xv = linspace(min(P(:,1)), max(P(:,1)), N);
yv = linspace(min(P(:,2)), max(P(:,2)), N);
[X,Y] = ndgrid(xv, yv);
Z = griddata(P(:,1), P(:,2), P(:,3), X, Y);
Warning: Duplicate data points have been detected and removed - corresponding values have been averaged.
figure
contourf(X, Y, Z, 35)
I looked at the first column of ‘P’ to see if reshaping would work. It will not, because the first indices of the different unique values of ‘P(:,1)’ do not have constant distances between them.
The data simply do not appear to be smooth (i.e. may have limited precision), and that is reflected in the contours even with a relatively high precision in the interpolating matrices.
This is likely as good as it gets.
.
  18 个评论
Star Strider
Star Strider 2022-10-21
As always, my pleasure!
This was an interesting problem!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by