Keeping colors consistent between figures

2 views (last 30 days)
John
John on 14 Feb 2013
Hello, I have basic MATLAB (2012b), and no toolboxes. I've written the below program (with help) to plot data over a map, and turn the contours transparent so the map below can be seen. I used the contourfcmap (can be found on MATLAB Central, I added varargout{1} = c; and varargout{2} = h; to the end of the function to return c, h), which initially makes the figure have consistent colors, but once I use clabel the colors revert to whatever colormap it wants. I also tried commenting out the clabel part, and when I do this the findobj/facealpha now changes the colors back. I'd like to have the same color levels between figures (so 30-35 m/s is always colored the same color). Is there a way to make clabel and findobj use the same colormap I used in contourfcmap?
for da_month = 1:2 for da_level = 1:2
if da_month == 1, da_month2 = 'January'; da_month3='1'; end;
if da_month == 2, da_month2 = 'February'; da_month3='2'; end;
if da_level == 1, da_level2 = '10mb'; end;
if da_level == 2, da_level2 = '30mb'; end;
file_str = ['c:\data2\mid_east_month_' da_month3 '_hr_24_lvl_00' da_level2 '.csv'];
B = xlsread(file_str); %read in the wind data from excel
da_grid = zeros(25, 49); %initialize matrix with zeros
V = [0:5:60]; %vector of levels for contouring
for i = 1:25 %convert lat/lon data in column form to x,y grid
for j = 1:49
row_num = j + i*49 - 49;
da_grid(i,j) = B(row_num,10);
end
end
lon = 30:2.5:150; %vector of longitude values
lat = 55:-2.5:-5; %vector of latitude values
lat = lat'; %transpose to column vector
cfig = figure('Position', [100, 100, 1400, 800]); %set position of figure on screen
da_map = 'c:\data2\the_map.gif'; %line map of the region
[I,Imap] = imread(da_map); %read in the map
Itc = ind2rgb(I,Imap); % convert image with indexed colors to true color image
ih = image('XData',lon([1 end]),'YData',lat([1 end]),'CData',Itc); %show image
hold on; %now do the data contours
[c, h] = contourfcmap(lon, lat, da_grid, V, jet(12));
set(gca, 'Ytick', -5:5:55);
set(gca, 'xtick', 30:10:150);
cl = clabel(c,h,'FontSize',8,'BackgroundColor','w'); %make contour labels
for i=cl'
istring = get(i,'String');
set(i,'String',[istring(:)', ' m/s']);
end
chf = findobj(h,'-property','FaceAlpha');
set(chf,'FaceAlpha',.3)
yl = ylabel('Latitude (degrees)');
xl = xlabel('Longitude (degrees)');
da_title = [da_month2 ' ' da_level2 ' Wind Speed (m/s)'];
title(da_title);
hold off;
da_title = ['c:\data2\wind_speed_' da_month2 '_' da_level2];
print(gcf, '-djpeg', '-r500', da_title);
close
end
end

Answers (0)

Categories

Find more on Colormaps 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!