ssb
ssb

Reputation: 3

Plotting 2d data in matlab with different colours according to value

I have a 2d array that has values -1 and 1. How do I make the imagesc(lattice) appear in 2 specific colours? Right now it shows red for -1, blue for 1, and green for 0. I want to make the places with 0 appear white.

Upvotes: 0

Views: 219

Answers (2)

adalca
adalca

Reputation: 145

sounds like you need to set the colormap. If you only have three values, you might set:

cmap = [0 0 1; 1 1 1; 1 0 0]; % sets the colors to blue, white, red\
imagesc(data); colormap(cmap);

Upvotes: 1

Luis Mendo
Luis Mendo

Reputation: 112659

You need to set the colormap with those three colors:

cmap = [0 0 1; %// blue
        1 1 1; %// white
        1 0 0] %// red
colormap(cmap)

Upvotes: 0

Related Questions