MATLAB Answers

laurie
0

Creating a customized grid on a imagesc() figure

Asked by laurie
on 19 Apr 2012
Hi,
I have a matrix of values between -1 and 1, I look it up with imagesc().
I would like to trace a customized grid over that image to delimit portions of the "matrix" (datapoints that share a common property).
I thougt it would work to make up a second matrix with lines and rows full of NaNs or Inf or some special value.
But imagesc() will trace NaN and Inf in the color of the min and max in the matrix, not some special color.
So, is there a way to trace a grid on top of imagesc(), or to set the colormap in such a way that Inf (for example) are renderred black and the other values are renderred as in the normal colormap "jet"?
Thank you very much laurie

  0 Comments

Sign in to comment.

1 Answer

Answer by Walter Roberson
on 20 Apr 2012
 Accepted Answer

Create a second image located at exactly the same position as the first, with the lines that you want, and with AlphaData set to 0 where the underlying image should show through, and 1 where the overlay should show through. The second image would have to be truecolor (RGB) to use different colors than are in the original image. Note that if you do this then you will need to use the OpenGL renderer as it is the only one that supports transparency.
Alternately after drawing your base image, use line() specifying RGB colors to draw on the grid.
It is not possible to "exempt" particular values from the colormap: if you are using pseudocolor then every color in the image must appear somewhere in the colormap.

  2 Comments

thank you. the first solution seems too complicated for me so i'll try with line() and come back :-)
thanks, it worked :)

Sign in to comment.