2
votes

I want to use imagesc to plot a quantity where all of positive, negative, and close-to-zero values are important. I want the close-to-zeros to be black, but there is no default colormap that provides such a feature.

For example, using colormap(hot) assigns black to the lowest (in this case: negative) number, which looks bad:

figure, imagesc(Xvalues, Yvalues, Quantity) colorbar, colormap(hot), axis equal, axis off enter image description here

Observe that 0 is assigned some unflashy red, which makes the regions of vanishing value hard to see.

Is there any way to use (e.g.) colormap(hot) for the positive values and some blue-ish colormap for the negative values, with both meeting at a black zero?

1
@AnderBiguri Wow, how did I miss that with my beforehand searches. Thank you! - GDumphart

1 Answers

1
votes

EDIT: I see that a link to a similar question is posted as a comment to the question here. The answer provided there is much better than mine.

You can make a custom colormap. Colormaps have three columns and any number of rows. Each column represents one color (Red,Green,Blue, respectively). For example, if you want a color map from red to blue you could make one with:

mymap = [zeros(256,2),linspace(1,0,256)';linspace(0,1,256)', zeros(256,2)]

and then use it with

colormap(mymap)

I don't know of an easy way to make black equal zero although one must exist. The best advise I can give you to make that work is to calculate how many rows each color needs based on your minimum and maximum values.