Contour plot with positive and negative data and logarithmic colormap

10 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 7 Nov. 2011
Bearbeitet: Walter Roberson am 20 Jun. 2018
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.

Weitere Antworten (0)

Kategorien

Mehr zu Color and Styling finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by