tiswas
tiswas

Reputation: 2101

Matlab - set specific color for value in pcolor

I've created a pcolor whose caxis ranges from -3 to 3. However, within the data I've got lots of points whose value are exactly 1000. What I'd like to do is keep the colouring the same for all the other points, but set the colour for any point whose value is 1000 to black. Does anyone have any ideas how I could do this..?

Thanks a lot in advance, Adam

--EDIT--

I am currently creating the plot using a mapping tool for pcolor, m_pcolor, as follows (see here for details):

m_proj('Robinson')
h = m_pcolor(Lon', Lat', input_matrix);
m_coast('Color', 'k', 'LineWidth', 1);
set(h,'EdgeColor','none');

Upvotes: 3

Views: 11605

Answers (2)

H.Muster
H.Muster

Reputation: 9317

If black as the color for values that equal 1000 is not a strict requirement, you can simply set these values to NaN by

a(a==1000) = nan; 

The function pcolor will draw the nan values in white.

~edit~
To display the nan values in black, you might change the background of the axis to black:

set(gca, 'color', [0 0 0]);
hold on; 
pcolor(a); 

~edit2~
If you cannot change the background, try the following work around:

h1 = pcolor(ones(size(a))); 
hold on; 
set(h1, 'facecolor', [0 0 0]); 
pcolor(a); 

This draws two surfaces above each other with the lower one set to black.

Upvotes: 3

mars
mars

Reputation: 804

As H.Muster wrote, you can set the values equal to 1000 to NaN. In this case the axis color shows through, which is white by default. If you want it to be black, you can set the 'Color' property of the axis object:

a=[1 2 4; 3 NaN 5; 6 7 8];
pcolor(a);
set(gca, 'Color', 'Black')

Upvotes: 1

Related Questions