How to get logarithmic colorbar in MATLAB R2012a for 3D surface plot?
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to surface plot using following data with proper colorbar (log scale) but the result dont show color variation. Also, colorbar do not appear in log scale. Please help me out to fix this problem.
n=[2 5 10 15];
I=[1e-4 5e-4 1e-3 5e-3 1e-2 5e-2 1e-1 5e-1 1];
GB_RR=[1.2E26 6E26 2.4E27 6E27 1.2E28 6E28 1.2E29 6E29 2E31; ...
1.4E26 6.5E26 2.62E27 6.3E27 1.3E28 6.7E28 1.5E29 6.5E29 2.5E31; ...
1.53E26 6.72E27 2.84E27 6.9E27 1.5E28 6.9E28 1.9E28 6.64E29 2.7E31; ...
1.73E26 6.85E27 2.96E27 6.9E27 1.65E28 7.1E28 2.2E28 6.84E29 2.92E31];
surf(I,n,(GB_RR))
hold on
n1=[2 5 10 15];
I1=[1e-4 5e-4 1e-3 5e-3 1e-2 5e-2 1e-1 5e-1 1];
GB_RR1=[7.00E+26 8.00E+27 6.00E+28 8.50E+28 9.00E+29 4.00E+30 9.50E+30 7.00E+31 7.00E+32
7.20E+26 8.24E+27 6.30E+28 8.75E+28 9.30E+29 4.50E+30 1.50E+31 7.40E+31 7.40E+32
7.42E+26 8.44E+27 6.50E+28 8.85E+28 9.53E+29 4.85E+30 1.75E+31 7.84E+31 7.94E+32
7.72E+26 8.74E+27 6.80E+28 8.99E+28 9.83E+29 5.00E+30 2.10E+31 7.99E+31 8.30E+32];
surf(I1,n1,(GB_RR1))
2 commentaires
Walter Roberson
le 6 Fév 2021
It has been a number of years since R2012a.
If I recall correctly:
h = colorbar(); %used to return an axes
set(h, 'YScale', 'log')
No promises. I do not have R2012a installed to test with at present.
Réponses (1)
Walter Roberson
le 6 Fév 2021
When you use color mapping, color is always assigned by linear interpolation:
crange = caxis();
cmap = colormap(); %colormap that is in effect right now
numcolor = size(cmap,1);
if value < crange(1)
colorindex = 1;
elseif value > crange(2)
colorindex = numcolor;
else
colorindex = floor((value - crange(1)) / (crange(2) - crange(1)) * (numcolor-1)) + 1;
end
color_here = cmap(colorindex,:);
That is, distance away from the lowest value expressed a linear proportion of the distance between the two color endpoints, and map that by the number of colors available to get the color index.
Always
No matter whether you have set the colorbar axes to draw as log or not, the mapping is always done linear.
What should you do to have a log-based color representation?
This: calculate the color or color indices yourself and pass it as the CData to surf. For example,
C = log10(GB_RR) - 25;
surf(I, N, GB_RR, 'CData', C, 'edgecolor', 'none')
2 commentaires
Aurelien Gregor
le 27 Juil 2021
So is it possible to get a log-based color representation and a logscale colorbar ?
Walter Roberson
le 27 Juil 2021
You could supply whatever cdata you want and also set the colorbar y scale.
I seem to recall that they added an additional way to change the colorbar scale but I would need to recheck.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!