i wanted to make a second scale on the colorbar but the values of the ticks are off, for example 0.2 should be 14.33 , 0.4 should be 13.57 and so on.
this is the relevant bit of code:
hFig = figure('Name','False Color Luminance Map', 'ToolBar','none', 'MenuBar','none');
% Create/initialize default colormap of jet.
cmap = parula(16); % or 256, 64, 32 or whatever.
% Now make lowest values show up as black.
cmap(1,:) = 0;
% Now make highest values show up as white.
cmap(end,:) = 1;
imshow(J,'Colormap',cmap) % show Image in false color
colorbar % add colorbar
h = colorbar; % define colorbar as variable
caxis auto
y_Scl = (1/C);
yticks = get(h,'YTick');
set(h,'YTickLabel',sprintfc('%g', [yticks.*y_Scl]))
ylabel(h, 'cd/m^2')% add unit label
BarPos = get(h,'position');
haxes = axes('position',BarPos,'color','none','ylim',[0 150]);
set(haxes,'YTickLabel', sprintfc('%g', log10(yticks.*y_Scl/108000)/-0.4));
in my opinion the error has to be somewhere at the last two lines.
EDIT: when i change haxes = axes('position',BarPos,'color','none','ylim',[0 150]); to haxes = axes('position',BarPos,'color','none','ylim',[0 150]); i get this all the right values are there but the are not aligned right!
答案 0 :(得分:1)
BarPos = get(h,'position');
haxes = axes('position',BarPos,'color','none','ylim',[0 115]);
set(haxes,'YTickLabel', sprintfc('%.3g', log10(yticks.*y_Scl/108000)/-0.4));
yt1 = get(h, 'YTick');
yL1 = get(h, 'YLim');
t1ratio = (yt1 - yL1(1))./(yL1(2)-yL1(1));
yL2 = get(haxes, 'YLim');
yt2 = t1ratio .* (yL2(2)-yL2(1)) + yL2(1);
set(haxes, 'YTick', yt2)
这对我的问题很有用