How can I color individual patches in my contour plot in MATLAB 7.10 (R2010a)?

1 view (last 30 days)
I would like to generate a filled contour plot with a single contour line (at z=0) and two different colors, where neither color is white. When I run the COUNTROUF command, one of the regions always seems to plot as white. I would like to change the white color to some other colors.
Reproduction Steps:
[x,y,z] = peaks;
contourf(x,y,z,[0 0])

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 23 Aug 2010
This is an expected behavior. Since we are displaying the contour plot at z = 0, the white patches we get from the reproduction steps you provided are a part of the axes background. The axes background color can be set in the command text or from the axes properties editor. The small circular patch at the center, though has level of zero, is an individual patch so needs to be colored separately. Execute the following MATLAB code to generate the contour plot with two colors:
[x,y,z] = peaks;
[c,h] = contourf(x,y,z,[0 0])
% c contains contour matrix and h is the handle
ccc = get(h, 'children'); % Get different patches
set(ccc(1),'facecolor','r')
% Center patch. Color can be changed from red ‘r’ to other colors
set(ccc(2),'facecolor',[rand(1,3)])
% Left and bottom patches filled with a random color
set(gca,'color','r') % Set background color

More Answers (0)

Categories

Find more on Contour Plots in Help Center and File Exchange

Tags

Products


Release

R2010a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!