1
votes

I want to plot smooth contour plot from X Y Z matrix.

sf = fit([X Y] Z, 'poly23');
plot(sf);

I have not enought smooth curve.. What I need?

enter image description here

1
what is your X Y and Z? it would help more if we have an example of the data you are trying to plot :) - Lincoln Cheng
it's a column of data. they are too big to attach :( Z is an intensity at the point (X,Y) - delkov

1 Answers

1
votes

You can use the functions such as griddata and csaps. Together they will lead you to the result as smooth as you wish. The first function adds additional points to your data matrix set. The second one makes the result smoother. The example of the code is below. In the example smoothing is done first in X direction and then in Y direction. Try to play around with the resolution and smoothing_parameter (the current set of these parameters should be OK though).

x = min_x:step_x:max_x;
y = min_y:step_y:max_y;
resolution = 10;

xg = min_x:(step_x/resolution):max_x;
yg = min_y:(step_y/resolution):max_y;
[X,Y] = meshgrid(x,y);
[XG,YG] = meshgrid(xg,yg);    


smoothing_parameter = 0.02;
fitted = griddata(X,Y,Z,XG,YG,'cubic');
fitted_smoothed_x = csaps(xg,fitted,smoothing_parameter,xg);
fitted_smoothed_xy = csaps(yg,fitted_smoothed_x',smoothing_parameter,yg);

surf(XG,YG,fitted_smoothed_xy');

EDIT: If you want to get just a contour plot, you can do, for example, as presented below. As I don't have the real data, I will use build-in function peaks to generate some.

[X,Y,Z] = peaks(30);
figure
surfc(X,Y,Z)
view([0 90])
zlim([-10 -8])

Here you just look at your contour plot from above being below the surface.