Azzera filtri
Azzera filtri

Methods for smoothing contour lines

7 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Star Strider
Star Strider il 20 Ott 2022
Modificato: Star Strider il 20 Ott 2022
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 Commenti
Andrew Sol
Andrew Sol il 21 Ott 2022
And thank you for not passing by!
Star Strider
Star Strider il 21 Ott 2022
As always, my pleasure!
This was an interesting problem!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Contour Plots in Help Center e File Exchange

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by