I want to represent data with 2 variables in 2D format. The value is represented by color and the 2 variables as the 2 axis. I am using the contourf function to plot my data:
clc; clear;
load('dataM.mat')
cMap=jet(256); %set the colomap using the "jet" scale
F2=figure(1);
[c,h]=contourf(xrow,ycol,BDmatrix,50);
set(h, 'edgecolor','none');
xlim([0.0352 0.3872]);
ylim([0.0352 0.3872]);
colormap(cMap);
cb=colorbar;
caxis([0.7 0.96]);
% box on;
hold on;
Both xrow and ycol are 6×6 matrices representing the coordinates. BDmatrix is the 6×6 matrix representing the corresponding data. However, what I get is this:
The following is the xrow and yrow matices:
The following is the BDmatrix matices:
Would it be possible for the contour color to vary smoothly rather than appearing as straight lines joining the data points? The problem of this figure is the coarse-granularity which is not appealing. I have tried to replace contourf with imagec but it seems not working. I am using MATLAB R2015b.
Best Answer
You can interpolate your data.
Choose the "smoothness" of the new plot via the parameter
newpoints
.To reduce the Color edges, you can increase the number of value-steps. By default this is 10. The following code increases the number of value-steps to 50:
A 3D-surf plot would be more suitable for very smooth color-shading. Just rotate it to a top-down view. The surf plot is also much faster than the contour plot with a lot of value-steps.
Note 1: Cubic interpolation is not shape-preserving. That means, the interpolated shape can have maxima which are greater than the maximum values of the original
BDmatrix
(and minima which are less). IfBDmatrix
has noisy values, the interpolation might be bad.Note 2: If you generated
xrow
andyrow
by yourself (and know the limits), than you do not need that min-max-extraction what I did.Note 3: After adding screenshots of your data matrices to your original posting, one can see, that
xrow
andycol
come from anndgrid
generator. So we also must use this here in order to be consistent. Sinceinterp2
needsmeshgrid
we have to switch togriddedInterpolant
: