show regular intervals in the colourbar

조회 수: 3 (최근 30일)
Francesco Marchione
Francesco Marchione 2021년 9월 27일
답변: Mathieu NOE 2021년 9월 27일
I would like to have the colourbar displaying values for regular intervals: that is, I would like to have the colourbars displaying both extremes (max and min) and a fixed number of intermediate values (intervals), automatically.
T1 = readtable('SLJ20 PEEL.xlsx', 'VariableNamingRule','preserve');
% First10Rows = T1(1:10,:)
% T1Sz = size(T1)
VarNames = T1.Properties.VariableNames;
N = 50; % Interpolation Matrix Size
xv = linspace(min(T1{:,1}), max(T1{:,1}), N); % Create Vector
yv = linspace(min(T1{:,2}), max(T1{:,2}), N); % Create Vector
[Xm,Ym] = ndgrid(xv,yv); % Create Interpolation Matrices
Zm = griddata(T1{:,1}, T1{:,2}, T1{:,3}, Xm, Ym); % Interpolate
figure
surfc(Xm, Ym, Zm)
grid on
shading interp
set(0, 'DefaultTextInterpreter', 'latex')
hcb = colorbar;
xlabel(hcb,'[{\it Pa}]');
hcb.Label.Interpreter = 'latex';
set(hcb,'TickLabelInterpreter','latex')
colormap(jet(50))
title ('EPX1','FontSize',13,'interpreter', 'latex')
set(0, 'DefaultTextInterpreter', 'latex')
hcb = colorbar;
hcb.TickLabelInterpreter='latex';
% ColorbarRulerProperties = hcb.Ruler
hcb.Ruler.TickLabelFormat = '%.2f';
set(hcb, 'Ticks', sort([hcb.Limits, hcb.Ticks]))
set(gca,'TickLabelInterpreter','latex')
% tix = hcb.Ticks;
% expstr = @(x) [x(:).*10.^ceil(-log10(abs(x(:)+(x==0)))) floor(log10(abs(x(:)+(x==0))))];
% tixexp = expstr(tix(:))
% tixexplbl = compose('%.2f \\times 10^{%2d}',[tixexp(:,1) fix(tixexp(:,2))])
% hcb.TickLabels = tixexplbl;
xlabel('{\it x} [{\it mm}]')
ylabel('{\it y} [{\it mm}]')
zlabel('{\it} Shear stress [{\it MPa}]')

채택된 답변

Mathieu NOE
Mathieu NOE 2021년 9월 27일
hello Francesco
here a small update of your code and the result
see the line where I defined the number of ticks for colorbar
T1 = readtable('SLJ20 PEEL.xlsx', 'VariableNamingRule','preserve');
% First10Rows = T1(1:10,:)
% T1Sz = size(T1)
VarNames = T1.Properties.VariableNames;
N = 50; % Interpolation Matrix Size
xv = linspace(min(T1{:,1}), max(T1{:,1}), N); % Create Vector
yv = linspace(min(T1{:,2}), max(T1{:,2}), N); % Create Vector
[Xm,Ym] = ndgrid(xv,yv); % Create Interpolation Matrices
Zm = griddata(T1{:,1}, T1{:,2}, T1{:,3}, Xm, Ym); % Interpolate
figure
surfc(Xm, Ym, Zm)
grid on
shading interp
set(0, 'DefaultTextInterpreter', 'latex')
hcb = colorbar;
xlabel(hcb,'[{\it Pa}]');
hcb.Label.Interpreter = 'latex';
set(hcb,'TickLabelInterpreter','latex')
colormap(jet(50))
title ('EPX1','FontSize',13,'interpreter', 'latex')
set(0, 'DefaultTextInterpreter', 'latex')
hcb = colorbar;
hcb.TickLabelInterpreter='latex';
ColorbarRulerProperties = hcb.Ruler
hcb.Ruler.TickLabelFormat = '%.2f';
% set(hcb, 'Ticks', sort([hcb.Limits, hcb.Ticks]))
%%%%%%%%%%%%
Nticks = 10; % define number of ticks displayed in colorbar
aa = hcb.Limits;
CBAR_ticks = linspace(aa(1),aa(2),Nticks);
set(hcb, 'Ticks', CBAR_ticks);
%%%%%%%%%%%%
set(gca,'TickLabelInterpreter','latex')
% tix = hcb.Ticks;
% expstr = @(x) [x(:).*10.^ceil(-log10(abs(x(:)+(x==0)))) floor(log10(abs(x(:)+(x==0))))];
% tixexp = expstr(tix(:))
% tixexplbl = compose('%.2f \\times 10^{%2d}',[tixexp(:,1) fix(tixexp(:,2))])
% hcb.TickLabels = tixexplbl;
xlabel('{\it x} [{\it mm}]')
ylabel('{\it y} [{\it mm}]')
zlabel('{\it} Shear stress [{\it MPa}]')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Colormaps에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by