Contour plot with positive and negative data and logarithmic colormap
10 次查看(过去 30 天)
显示 更早的评论
I'd like to make a contour plot of data that has both positive and negative values, with a colormap that varies logarithmically. I am envisioning a colormap that has positive data in red, which fades to white logarithmically as the values approach zero; similarly, the negative data would be colored blue and fade to white logarithmically as the absolute value of the data approaches zero. Any help would be greatly appreciated.
Thanks in advance,
Brett
0 个评论
采纳的回答
Walter Roberson
2011-11-7
编辑:Walter Roberson
2018-6-20
You can do reasonable things for abs(x) >= 1, but for abs(x) < 1 you have problems.
The classical realmin for MATLAB is around 1E-308, which is about 2^(-1023). However, denormalized numbers exist, and those add another 53-ish bits of binary range, giving you approximately 1075 or so bits in 0 < x < 1 . There is, though, no equivalent to denormalized numbers at the upper end of the range, so to be fair, you will need to allocate more than half of your colormap to values in -1 < x < 1 -- a range that will probably be lightly populated. Yah, you could use quarter of your map to fade white to medium-gray (and another quarter to fade back for the negatives), but is that really what you want?
I would suggest that you probably want to cheat on your log representation. For example, if you were to calculate
fudge_zero = 1/10;
extreme = max(abs(x(:))) * (1+eps);
L = logspace(fudge_zero,extreme, 128) %256 entry colormap
logmap = [-fliplr(L), L];
Once you had done that, then
[bins, xbinidx] = histc(x, logmap);
and then you would plot using uint8(xbinidx-1) as the colormap index for each x.
The fudge_zero prevents sufficiently low theoretical absolute values from contributing lots of bins. Adjust it however you like, understanding that between -fudge_zero to +fudge_zero all values will be mapped to the same index.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Color and Styling 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!