MATLAB: How to ensure the polar axes lines remain visible after I overlay the polar axes with a contour plot in MATLAB 7.6 (R2008a)

dwhhgwaitMATLAB

When I execute the following code,
polar(0);
hold on;
n = 6; r = (0:n)'/n; theta = pi*(-n:n)/n;
X = r*cos(theta); Y = r*sin(theta); C = r*cos(2*theta);
pcolor(X,Y,C)
I first see an empty polar axes on top of which the contour is drawn. The axes grid lines then become hidden. I would like to know how to make them visible.

Best Answer

Polar axes created by the POLAR function in MATLAB 7.6 (R2008a) are simply a set of patch, line and text objects drawn in the right regions to make it look like an axis. This is different from the regular non-polar axes grid lines which are not objects in the handle graphics hierarchy and rendered differently. Therefore, when the contour is overlaid on the polar axes, it hides the grid line and text objects underneath it.
To display the axes grid lines and text objects you will need to extract their handles and set their move them to the top of the graphics hierarchy using UISTACK when all other plotting is complete. For example,
polar(0,0);
hold on
% Extract handles to polar grid lines and text labels
set(0,'ShowhiddenHandles','on');
polarline = findobj(gca,'type','line');
polartext = findobj(gca,'type','text');
set(0,'ShowhiddenHandles','off');
n = 6; r = (0:n)'/n; theta = pi*(-n:n)/n;
X = r*cos(theta); Y = r*sin(theta); C = r*cos(2*theta);
pcolor(X,Y,C)
% Move the polar grid lines to the top
uistack(polarline,'top');
uistack(polartext,'top');
In addition, you could also set the object's EraseMode property to 'xor' which instrucst MATLAB to render them with a color that contrasts whatever is underneath it. Note that the axes grid line colors will no longer be black in all areas.
% Change EraseMode property of objects
set(polarline,'EraseMode','normal');
set(polartext,'EraseMode','xor');
For more information on UISTACK, line properties, text properties and displaying contours in polar coordinates, consult the documentation by executing,
doc uistack
doc line_props
doc text_props
web([docroot '/techdoc/creating_plots/f10-2524.html#f10-2674'])