MATLAB Matlab -- how to make a smooth contour plot?

AI Thread Summary
To represent data with two variables in a 2D format using MATLAB, the contourf function is employed to plot a 6x6 matrix (BDmatrix) against two coordinate matrices (xrow and ycol). However, the resulting plot exhibits coarse granularity, leading to undesirable straight lines between data points. To achieve a smoother color transition, it is suggested to increase the data resolution, potentially using a 200x200 grid. Alternatives such as the "shading interp" option in MATLAB can help with color interpolation. Additionally, functions like interp2() or griddedInterpolant() can be utilized to create denser data points before plotting with contourf, enhancing the visual quality of the contour representation.
kelvin490
Gold Member
Messages
227
Reaction score
3
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:

load('data.mat')
cMap=jet(256);
F2=figure(1);

[c,h]=contourf(xrow,ycol,BDmatrix);
set(h, 'edgecolor','none');
Both xrow and ycol are 6x6 matrices representing the coordinates. BDmatrix is the 6x6 matrix representing the corresponding data. However, what I got the picture as attached.

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.
 

Attachments

  • BD.jpg
    BD.jpg
    25 KB · Views: 1,955
Physics news on Phys.org
You are seeing the effects of plotting on just a 6x6 grid. The contours would look smooth if your data were on, say, a 200x200 grid. I don't know what to do except to generate denser data or maybe look for software that uses different contour generation methods.
 
Try using interp2() or griddedInterpolant() to make more data point locations before passing the image to contourf().
 

Similar threads

Replies
2
Views
2K
Replies
4
Views
3K
Replies
1
Views
2K
Replies
1
Views
3K
Replies
1
Views
6K
Replies
9
Views
5K
Replies
7
Views
3K
Replies
1
Views
2K
Replies
1
Views
2K
Back
Top