MATLAB: How to get the colors of contour plot after MATLAB R2014b

cdatacmapcolormaphg2lineMATLABpatch

I have created a "contourf" plot, and because of limitations with the "contour" functions, I would like to get the contour data and replot it using other functions.
Before R2014b, contour plots had "patch" objects that I could access. I could get the "CData" from each layer of the contour plot. With HG2, charting objects no longer use patches. How do I recreate get the contour plot's color data?

Best Answer

These are the steps that you can follow to accomplish your workflow after R2014b:
1. Create a contour plot with your data and save the contour matrix in a variable.
2. Parse the contour matrix to save all the vertices in each contour level. Concatenate all the contours for a given level into one vector, with breaks delimited by NaN, and a NaN at the end of the vector.
3. Plot each vector as a patch and just show the edges. Please note that the advantage of using “patch” over “plot” is that you can set the “CData” for each patch (one per level) to that level’s value. If you used the "flat" option for "LineColor" in your contour plot, you can use the "flat" option for "EdgeColor" in the "patch" properties and recreate the color scheme.
You cannot use the "plot" function to recreate a contour plot because they create "line" objects, which do not use the colormap.
Please refer to the “patch” and “contour” properties pages at these links for more information: