How do I make a contour?

4 visualizzazioni (ultimi 30 giorni)
민제 강
민제 강 il 16 Giu 2021
Commentato: John D'Errico il 21 Feb 2024
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.
sample_contour
  2 Commenti
SALAH ALRABEEI
SALAH ALRABEEI il 16 Giu 2021
It depends on your data, but you can play with the intensity level instead of 20 ( increase/decrease).
민제 강
민제 강 il 16 Giu 2021
I've tried, but it still doesn't work.

Accedi per commentare.

Risposte (1)

Shivam Lahoti
Shivam Lahoti il 21 Feb 2024
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 Commento
John D'Errico
John D'Errico il 21 Feb 2024
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.

Accedi per commentare.

Categorie

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

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by