Matlab -- how to make a smooth contour plot?

In summary, the conversation was about representing data with 2 variables in a 2D format using the contourf function in MATLAB. The speaker was experiencing coarse-granularity in their current plot and wanted to know if there was a way to make the contour color vary smoothly. They had tried using imagec but it was not working and were considering generating denser data or using a different software. The expert suggested using the "shading interp" option in MATLAB or using interpolation functions such as interp2() or griddedInterpolant() to generate more data points.
  • #1
kelvin490
Gold Member
228
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,901
Physics news on Phys.org
  • #2
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.
 
  • #4
Try using interp2() or griddedInterpolant() to make more data point locations before passing the image to contourf().
 

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

1. How do I create a contour plot in Matlab?

To create a contour plot in Matlab, you can use the contour function. This function takes in a set of x and y coordinates, as well as a corresponding z value for each point, and plots contour lines connecting points with the same z value.

2. How can I make my contour plot smoother?

To make a smoother contour plot, you can increase the number of points in your data set. This will result in more closely spaced contour lines and a smoother appearance. You can also use interpolation techniques, such as cubic or spline interpolation, to create a smoother contour plot.

3. How do I change the color scheme of my contour plot?

You can change the color scheme of your contour plot by using the colormap function. This function allows you to specify a color map to use for your contour plot, such as a gradient or a predefined color scheme like jet or hot.

4. Can I add labels and a legend to my contour plot?

Yes, you can add labels and a legend to your contour plot using the xlabel, ylabel, and legend functions. These functions allow you to specify the labels and legend entries, as well as customize their appearance.

5. How can I save my contour plot as an image file?

To save your contour plot as an image file, you can use the saveas function. This function takes in the figure handle and a file name, and saves the plot as an image in the specified file format, such as .png or .jpg.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top