Problem changing FaceColor in contourm
显示 更早的评论
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
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!