Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
assigning specific color to NaN values in imagesc

Subject: assigning specific color to NaN values in imagesc

From: chris.g.krautschik@intel.com (christof krautschik)

Date: 4 Nov, 2000 01:33:16

Message: 1 of 5

I am trying to plot a 2D matrix over a circular aperture of radius
unity through the imagesc command. The points ouside the radius are
assigned the value NaN since I would like them to be colored black in
the end. The points inside the circular area have values between -1.0
and +1.0 .

When I use imagesc along with colormap(jet(16)) the NaNs are plotted
deep blue since imagesc sets NaNs to the lowest value in the matrix
which is -1 in my case. When I create a new colormap, e.g colormap( [0
0 0;jet(16)]) then the area outside the aperture become indeed black
but so are some points now inside the circle as well. How to I resolve
this conflict?


What I want is that all points inside the circle have the colors of
jet(16) assinged to them while the points outside the circle should
all be black. Also, the colorbar should only show the scale from -1 to
+1 and the colors of jet(16) (I don't want black to show up in the
colorbar).

thanks,
Chris

Subject: assigning specific color to NaN values in imagesc

From: us

Date: 4 Nov, 2000 09:20:36

Message: 2 of 5

try this
hth
us
<<<---CODE beg--->>>
a=rand(10,10);
a(a<.75)=nan;

amin=min(a(:));
amax=max(a(:));
dmap=(amax-amin)/15;

colormap([[0 0 1];hot(16)]);
imagesc(a);
caxis([amin-dmap amax]);
colorbar;
axis image;

[iy,ix]=find(a==amin);
line(ix,iy,'marker','o',...
'markerfacecolor',[1 1 1],...
'markeredgecolor',[1 1 1]);
[iy,ix]=find(a==amax);
line(ix,iy,'marker','o',...
'markerfacecolor',[0 0 0],...
'markeredgecolor',[0 0 0]);

<<<---CODE end--->>>

In article <hvwo6l3gvw44@forum.mathforum.com>,
  chris.g.krautschik@intel.com (Christof Krautschik) wrote:
> I am trying to plot a 2D matrix over a circular aperture of radius
> unity through the imagesc command. The points ouside the radius are
> assigned the value NaN since I would like them to be colored black in
> the end. The points inside the circular area have values between -1.0
> and +1.0 .
>
> When I use imagesc along with colormap(jet(16)) the NaNs are plotted
> deep blue since imagesc sets NaNs to the lowest value in the matrix
> which is -1 in my case. When I create a new colormap, e.g colormap( [0
> 0 0;jet(16)]) then the area outside the aperture become indeed black
> but so are some points now inside the circle as well. How to I resolve
> this conflict?
>
> What I want is that all points inside the circle have the colors of
> jet(16) assinged to them while the points outside the circle should
> all be black. Also, the colorbar should only show the scale from -1 to
> +1 and the colors of jet(16) (I don't want black to show up in the
> colorbar).
>
> thanks,
> Chris
>


Sent via Deja.com http://www.deja.com/
Before you buy.

Subject: assigning specific color to NaN values in imagesc

From: us

Date: 4 Nov, 2000 10:12:49

Message: 3 of 5

... and
if you have R12prev / will have R12 you can peruse the nice new feature
of transparency mapping:
the code snippet creates a map <z> with full transparency for <nan>s.
hence, the axis (color: 0 .9 1) becomes visible; and <axis off> will
show the figure's background.
note that we use the full color range for ]min:max[.
hth
us

<<<---CODE beg--->>>
a=rand(10,10);
a(a<.75)=nan;

amin=min(a(:));
amax=max(a(:));

% create full transparency for <nan>s
z=a;
z(isnan(a))=0;
z(~isnan(a))=1;

colormap(hot(16));
imagesc(a);
colorbar;
set(gca,'color',[0 .9 1]);
alpha(z);
axis image;

[iy,ix]=find(a==amin);
line(ix,iy,'marker','o',...
'markerfacecolor',[1 1 1],...
'markeredgecolor',[1 1 1]);
[iy,ix]=find(a==amax);
line(ix,iy,'marker','o',...
'markerfacecolor',[0 0 0],...
'markeredgecolor',[0 0 0]);
<<<---CODE end--->>>


Sent via Deja.com http://www.deja.com/
Before you buy.

Subject: assigning specific color to NaN values in imagesc

From: chris.g.krautschik@intel.com (christof krautschik)

Date: 5 Nov, 2000 09:19:30

Message: 4 of 5

Thanks for your efforts.

This almost does the job for me expect that the colorbar also contains
the background color which I don't want. If I define my colormap as
follows

colormap([[0 0 0];autumn(256)]);

for example the lowest color value of black is not really noticable.
This is what I ended up doing. However for large color "blocks" like

colormap([[0 0 0];autumn(16)]);

it is noticable.

Any idea how to control colorbar so it won't show the black color
block?

thanks,
Chris

Subject: assigning specific color to NaN values in imagesc

From: us

Date: 5 Nov, 2000 15:45:10

Message: 5 of 5

when you create your <colorbar> you can do this

<<<--- CODE beg --->>>
% create a map with obvious <marker> at entry 1
cm=[[0 0 1];hot(16)];
colormap(cm);

% create a <colorbar> and keep handle
cbh=colorbar;

% retrieve the <cdata>s from its patch
cdh=get(cbh,'children');
map=get(cdh,'cdata');

% and leave the <marker> out
set(cdh,'cdata',map(2:end));

% NOW: adjust the <xticklabel> or <yticklabel>,
% depending on the layout of the bar (homework)!!!
<<<--- CODE end --->>>

hth
us

In article <5q59qv3n7qk4@forum.mathforum.com>,
  chris.g.krautschik@intel.com (Christof Krautschik) wrote:
> Thanks for your efforts.
>
> This almost does the job for me expect that the colorbar also contains
> the background color which I don't want. If I define my colormap as
> follows
>
> colormap([[0 0 0];autumn(256)]);
>
> for example the lowest color value of black is not really noticable.
> This is what I ended up doing. However for large color "blocks" like
>
> colormap([[0 0 0];autumn(16)]);
>
> it is noticable.
>
> Any idea how to control colorbar so it won't show the black color
> block?
>
> thanks,
> Chris
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us