Plotting contours in matlab

조회 수: 3 (최근 30일)
mukesh bisht
mukesh bisht 2021년 6월 22일
댓글: Bjorn Gustavsson 2021년 6월 22일
Hi
I have a data set (attached) for which I have plotted a scattered plot (Figure2) and a contour plot (Figure1). But, the contour plot doesn't look good, the boundary of contour plot is rough (i.e. not smooth). Please suggest some method to correct the contour plot or some other interpolation method.
My code:
For Scattered plot
x = D(:,1);y = D(:,2);z = D(:,3);pointsize = 10;
figure(2)
scatter(x,y,pointsize,z,'filled')
colormap jet;colorbar
For Contour plot
x = D(:,1);y = D(:,2);z = D(:,3);
xv = linspace((min(x)), max(x)); yv = linspace(min(y), max(y));
[Xm,Ym] = ndgrid(xv, yv);
Zm = griddata(x, y, z, Xm, Ym,'natural');
hold on
figure(1)
contourf(Xm, Ym, Zm, 200, 'LineStyle','none'); colormap jet; colorbar
  댓글 수: 1
Bjorn Gustavsson
Bjorn Gustavsson 2021년 6월 22일
Your best bet on removing the "prickly edge" is to artificially interpolate data along the "red-valued" boundary (parabolic, hyperbolic?) to add one (or two) dense perimeters along that edge - if that's appropriate or what you want.
Triangulation-based methods will return some peculiarly shaped triangles in that region from the data you have, that is what it is, it feels counterintuitive and "unfair" but if you zoom in and look at the triangulation you will see what happens (you'll have to do an explicit triangulation with delaunay - likely on a much smaller sub-grid and manually plot the triangulation). To some degree you might change that behaviour somewhat by scaling your x and y-values differently but that's a crutch.

댓글을 달려면 로그인하십시오.

답변 (1개)

KSSV
KSSV 2021년 6월 22일
편집: KSSV 2021년 6월 22일
You have to increase the number of points while using linspace. Now defualt it is 100.
n = 500 ; % change this value
xv = linspace((min(x)), max(x),n);
yv = linspace(min(y), max(y),n);

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by