Matlab -- how to make a smooth contour plot?

Click For Summary
SUMMARY

The discussion focuses on creating smooth contour plots in MATLAB using the contourf function. The user is working with MATLAB R2015b and is attempting to visualize data represented by two variables on a 6x6 grid, resulting in coarse contours. To achieve smoother contours, it is recommended to increase the data granularity, potentially using a 200x200 grid. Additionally, employing MATLAB's "shading interp" option and functions like interp2() or griddedInterpolant() can enhance the visual quality of the contour plot.

PREREQUISITES
  • Familiarity with MATLAB R2015b
  • Understanding of contour plotting using the contourf function
  • Knowledge of data interpolation techniques such as interp2() and griddedInterpolant()
  • Basic concepts of color mapping and shading in MATLAB
NEXT STEPS
  • Explore the use of MATLAB's "shading interp" for smoother color transitions in contour plots
  • Learn about data interpolation methods, specifically interp2() and griddedInterpolant()
  • Investigate techniques for generating denser datasets to improve contour plot resolution
  • Research alternative contour generation methods available in MATLAB or other visualization software
USEFUL FOR

This discussion is beneficial for data scientists, MATLAB users, and researchers who need to create visually appealing contour plots and improve data visualization techniques.

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,970
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