Code covered by the BSD License  

Highlights from
contourfcmap: filled contour plot with precise colormap


4.6 | 5 ratings Rate this file 73 Downloads (last 30 days) File Size: 8.66 KB File ID: #29638
image thumbnail

contourfcmap: filled contour plot with precise colormap



06 Dec 2010 (Updated )

Creates a filled contour plot, with more precise control over colors than contourf.

| Watch this File

File Information

This function creates a shaded contour plot, similar to that created by the contourf function. However, the relationship between a contourf plot and its colormap (i.e. exactly which color corresponds to each contour interval), can often be confusing and inconsistent, especially if your contour lines are not evenly spaced. This function instead allows the user to specify exactly which colors to use in each interval, and also to choose colors for regions that exceed the contour line limits.
Note: completely rewritten in preparation for new contourf plot objects in R2014b. Output of the new version has changed, so check back-compatibility. Requires Mapping Toolbox for R2014b and later.


Contourcs: To Obtain Contourc Output As A Struct Array inspired this file.

MATLAB release MATLAB 7.10 (R2010a)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (10)
02 Aug 2014 Kelly Kearney


Your x, y, and z data need to formatted in the same way as for the native contourf function, so you'll need to grid your data (not knowing the arrangement of the points in your vectors, I don't know whether you'd have to simply reshape, regrid, or use a scattered interpolant). Type help contourfcmap to see an example of use.

30 Jul 2014 CARLA QUISPE

hello ,
I have a matriz of 3 colums (x,y,z), how I should use the code to run the program. what of the three files I must to run firts
thanks a lot!

04 Mar 2013 Jan

Superb function, thanks.

15 Jan 2013 Franzi

exactly what I needed

30 Nov 2012 peter

great submission, thanks a lot

26 Jun 2012 Kelly Kearney

@Earle Wilson,

Both saturated low and high values should be colored by the colors defined by the 'lo' and 'hi' inputs, respectively; by default these are white, but you can set them to be the same as the first and last cmap values if you want a saturated effect. If you see a different result please send me an example and I'll look into it.

10 May 2012 Earle Wilson

great function! This saved me many hours of working around all the bugs in contourf.

The only (minor) short coming is that this function doesn't deal with saturated low values. Eg. if you enter:
and there are values in z < min(clev), they will be plotted as white spaces. This is an issue with contourf really, which I won't get into here. An easy fix is set all values in z outside the clev limits to min(clev) or max(clev). Eg.
toohigh = z>max(clev); z(toohigh) = max(clev);
loolow = z<min(clev); z(toolow) = min(clev);

19 Oct 2011 Kelly Kearney

Added minmax subfunction into main code (overlooked this dependency on a simple helper function in previous upload). Thanks, Karin and Aurelien, for pointing out that mistake.

18 Oct 2011 Aurelien Queffurust

I wanted to test your code but:
the minmax function which is required by your code is not shipped .

Another remark:
You have forgotten a bracket in the given example in the header of M-file:
[x,y] = meshgrid(linspace(0,1,100)
should be:
[x,y] = meshgrid(linspace(0,1,100))

Now waiting for minmax.m before rating.



09 May 2011 Tjaart de Wit

Great function! Thanks

07 Dec 2010

minor grammatical fix in description

19 Oct 2011

Fixed accidental omission of helper function in colorbar generation (minmax). Also corrected minor typo in example and added more informative example image.

30 Nov 2012

Fixed bug where new colorbar stole focus from axis.

23 Jul 2014

-Rewritten for R2014b, no longer relies on contourf object
-Added option to display all color levels evenly on the colorbar, regardless of value

03 Oct 2014

Corrected a bug in polygon generation where corner points of patches were out of order.

Contact us