Using colorbar with imagesc
1 view (last 30 days)
Show older comments
I have imported a 500 x 500 text file and have plotted the data using imagesc. I need all the cells in the text file containing a zero to be plotted white, but colour the rest of the data ie start the colorbar from 1 and include all the data up to the maximum number, but making everything that is a zero, white.
0 Comments
Accepted Answer
Adam
on 5 Dec 2016
Do you need white to actually appear on the colourbar? Doing this can be difficult because colorbars are usually e.g. 256 or 512 values so unless you have only that many data values you will always get multiple values falling in each colour bin since the minimum you could have is a single white colour bin covering e.g. 1/256th of your data.
You can manipulate your data to make this easier, but if you don't need the white to be on the colourmap, then I would just use AlphaData to make the 0 data transparent. If you need to you could create a white patch of the size of the axes under your image, but the axes themselves are white by default so you shouldn't need to do this.
2 Comments
Adam
on 5 Dec 2016
Then I would suggest to just create a mask for your data to use as AlphaData
e.g.
alphaMask = myData ~= 0;
set( hImage, 'AlphaData', alphaMask )
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!