Change specific colours in pcolour

조회 수: 2 (최근 30일)
Jason Baxter
Jason Baxter 2012년 8월 11일
Hi, i'm trying to change the background of my graphs so that NaN values come up as black.
I have tried putting the following commands in various places through out the plot program such as:
whitebg([0 0 0])
set(gca, 'Color', 'Black')
but nothing seems to work. I also need to change the colour of the 0 values to white. here is the plotting part of the program
figure('Visible','off') % observation u
plot1=pcolor(times, heights, obsArrayU);
set(plot1,'edgecolor','none');
title(['Observation of u for station: ' radarStr ' from ' ...
sDayStr '-' sMonthStr '-' sYearStr ' to ' eDayStr '-' eMonthStr '-' eYearStr ...
' for ' model ' model'], 'FontWeight','bold')
set(gca, 'Clim', [-50, 50]); colorbar;
colormap(jet(20)); xlabel(['Time ' timeLabelName]);
ylabel('Height (km)'); set(gca, 'XTick', xTickPoints);
set(gca, 'XTickLabel', date); %xticklabel_rotate;
n=get(gca,'YTick');
set(gca,'yticklabel',sprintf('%.1f |',n/1000'));
print('-djpeg', ...
['Images/obs__u_radar_' radarStr '_' model '_frm_' sYearStr sMonthStr sDayStr...
'_to_' eYearStr eMonthStr eDayStr])
any help would be appreciated, thank you

채택된 답변

Image Analyst
Image Analyst 2012년 8월 11일
You need to modify your colormap. What color are nan's coming up as now? You're setting CLim to [-50, 50] so what element of jet(20) shows up as 0? jet(1) is -50, and jet(20) is 50, so is 0 then jet(10) or jet(11)?
myColorMap = jet(20);
% Set 0 to white.
myColorMap(10,:) = [1 1 1];
colormap(myColorMap);
But why are you using pcolor in the first place? Why not use image() or imshow()? Why do you want to lose a row and a column of your data by using pcolor()? Did you not know that? Then just run this to prove it to yourself: pcolor(rand(4,4)).

추가 답변 (1개)

Jason Baxter
Jason Baxter 2012년 8월 11일
ah i figured it out, the background wasn't changing because figure('visible', 'off' was stopping it for some reason.
I will try using image or imshow now, i've never used them before, I was aware that I was losing column but didn't know how to fix it thanks again

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by