Home > Net >  Colorbar axis ticks changing color on 3D figure in Matlab
Colorbar axis ticks changing color on 3D figure in Matlab

Time:10-26

I've been trying to change the ticks on the colorbar axis on my 3D but I've encountered the problem where if I do so the color on the entire 3D figure changes. Basically what I'm trying to do is maintain the same kind of color range on the 3D figure while changing the color bar values from 0 - 80 to 50 - 450 instead without changing the color on the actual figure.

Thanks in advance!

clc;
clear all;
close all;

filename = ['*File pathway to the datafiles*' 'filenames.txt'];
T = readtable(filename);
tsize = size(T);
tsize (1);

filename = strcat('*File pathway to the datafiles*', string(T{1,1}));
heat = double(getHeatMap(filename));

%load('myMap2.mat');
figure
set(gcf,'Visible','on')
for i = 1:tsize
    filename = strcat('*File pathway to the datafiles*', string(T{i,1}));
    if dir(filename).bytes == 0
        continue;
    end
    heat = double(getHeatMap(filename));
    [X,tY] = meshgrid( linspace(1,400,size(heat,2)),linspace(0,2*pi,size(heat,1)));
    max_heat = max(heat, [], 'all');
    min_heat = min(heat, [], 'all');
    R = (((heat-min_heat)/(max_heat-min_heat))*50) 100;
    Y = cos(tY) .* R;
    Z = sin(tY) .* R;
    [nx, ny, nz] = surfnorm(X,Y,Z);
    nv = reshape([nx ny nz], size(nx,1),size(nx,2),3);
    CV = R;
    s = surf(X,Y,Z,heat,'VertexNormals',nv, 'EdgeColor','none');
    axis([0 400 -200 200 -200 200])
    colorbar
    colormap('parula')
    lighting gouraud
    camlight
    material dull
    caxis([0 80])
    drawnow
end
function heat = getHeatMap(filename)
s = dir(filename);
fin=fopen(filename,'r');
I=fread(fin,s.bytes,'uint8=>uint8');
w = uint16(I(1)) 256*uint16(I(2));
h = uint16(I(3)) 256*uint16(I(4));
skip = s.bytes - w*h   1;
IN = I(skip:1:s.bytes);
Z=single(reshape(IN,w,h));
Z=griddedInterpolant(Z');
y_range = linspace(1.0,single(h),256);
x_range = linspace(1.0,single(w),512);
heat = uint8(Z({y_range, x_range}));
end

enter image description here

After changing colorbar axis between the range 50 - 450 using caxis([50 450]) enter image description here

CodePudding user response:

The color of the surface is given by you, as the input heat to surf. It feels like the easy thing here is simply changing that input.

If you just do surf(X,Y,Z, heat*400/80 50 ,.... you should get what you want.

  • Related