Matlab -- how to make a smooth contour plot?

Click For Summary

Discussion Overview

The discussion focuses on creating a smooth contour plot in MATLAB using the contourf function. Participants explore methods to improve the visual quality of the contour representation of data with two variables, addressing issues related to grid size and data interpolation.

Discussion Character

  • Exploratory, Technical explanation, Debate/contested

Main Points Raised

  • One participant notes that the current 6x6 grid is likely causing the lack of smoothness in the contour plot and suggests using a denser grid, such as 200x200, for better results.
  • Another participant mentions the "shading interp" property in MATLAB, which may help interpolate colors between contour lines, although they cannot test it themselves.
  • A different suggestion involves using interpolation functions like interp2() or griddedInterpolant() to create more data points before applying contourf().
  • One participant expresses that replacing contourf with imagec did not yield the desired outcome, indicating a challenge in achieving smooth color variation.

Areas of Agreement / Disagreement

Participants generally agree that the grid size affects the smoothness of the contour plot, but multiple competing views on how to achieve a smoother representation remain. The discussion does not reach a consensus on the best approach.

Contextual Notes

Limitations include the dependence on the grid size and the potential need for denser data, as well as the unresolved effectiveness of suggested methods like shading interpolation and data interpolation functions.

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,977
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 ·
Replies
2
Views
2K
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
7K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K