Problem changing FaceColor in contourm
Show older comments
I am using contourm to make a filled contour plot on a lat/lon map. I want to customize the colors of the lines and fill so that there are only 6 filled colors shown, which I do by manually changing the 'Color' and 'FaceColor' parameters in the Children:
[~,h_Vp] = contourm(lat_Vp_mat,lon_Vp_mat,Vp_month_case_mat,SS_thresh,'Fill','on');
temp = get(h_Vp,'Children');
numthresh = length(SS_thresh);
for pp=1:numthresh
set(temp(pp),'Color',SS_colors{numthresh-pp+1})
set(temp(numthresh+pp),'FaceColor','flat')
end
This works for changing the line color. But when run inside of my script, it does not change the FaceColor; the changes to 'FaceColor' in the Children apparently get ignored and are overwritten back to default. If I stop the script to debug at the end of these lines of code and then copy and paste the code into the command line manually, it will correctly change the fill colors.
Anyone know how to fix this? Or an alternative way to do this?
Here is the code:
%%Define data
lat_mat = repmat(10:-1:1,10,1)';
lon_mat = repmat(1:10,10,1);
data_mat = lat_mat.^2+lon_mat.^2;
%%Define color thresholds
c_thresh = [20 50 80 120 130]; %contour thresholds
c_colors = {[.9 .9 .9] [.5 .75 0] [1 1 0] [1 .5 0] [1 0 0] [.5 0 0]};
%%Make filled contour plot
figure(1)
set(gcf,'Visible','on')
[~,h_pl] = contourm(lat_mat,lon_mat,data_mat,c_thresh,'Fill','on');
temp = get(h_pl,'Children');
numthresh = length(c_thresh);
for pp=1:numthresh
set(temp(pp),'Color',c_colors{numthresh-pp+1})
set(temp(numthresh+pp),'FaceColor','flat')
end
Accepted Answer
More Answers (0)
Categories
Find more on Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!