File Exchange Pick of the Week

Our best user submissions

Non-Uniform Contourf

Posted by Jiro Doke,

Jiro‘s pick this week is non-uniform contourf/imagesc/colorbar by Yuxin Jiang.

I discovered this File Exchange entry after seeing a question (note, the question is in Japanese) on MATLAB Answers. The user wanted to create a contourf with 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.


Next, let’s create a contour plot where the values between -1 and 1 are gray.

edges = -10:10;        % create 20 levels
cmap = parula(20);     % create colormap
cmap(10:11,:) = .5;    % set the color corresponding to -1~1 to gray

Then we call contourfnu.



Give it a try and let us know what you think here or leave a comment for Yuxin.

Get the MATLAB code

Published with MATLAB® R2017b

Add A Comment

Your email address will not be published. Required fields are marked *

Preview: hide