Non-Uniform Contourf
Jiro‘s pick this week isnon-uniform contourf/imagesc/colorbarbyYuxin Jiang.
I discovered this File Exchange entry after seeing aquestion(note, the question is in Japanese) on MATLAB Answers. The user wanted to create acontourfwith a particular color at a given range. There are probably a number of ways to achieve this, including the answer provided by Akira.
This entry by Yuxin gives the flexibility to specify non-uniformly spaced levels, as well as custom colormaps. Let’s take a look.
data = peaks;
First, a normal filled contour plot.
contourf(data) colorbar
Next, let’s create a contour plot where the values between -1 and 1 are gray.
edges = -10:10;% create 20 levelscmap = parula(20);% create colormapcmap(10:11,:) = .5;% set the color corresponding to -1~1 to gray
Then we callcontourfnu.
contourfnu(1:49,1:49,data,edges,cmap,[],[],'contourf')
Comments
Give it a try and let us know what you thinkhereor leave acommentfor Yuxin.
- Category:
- Picks
Comments
To leave a comment, please clickhereto sign in to your MathWorks Account or create a new one.