Problem with setting specified intervals with colorbar
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kevin Hanekom
am 16 Aug. 2021
Kommentiert: Kevin Hanekom
am 16 Aug. 2021
Good morning,
I am having problems setting specified intervals for my colorbar. I have tried reading the documentation, and looking at previous questions for the function, but nothing seems to work.
Heres the code,
clc; clear;
sig1c = .35031092712186400;
sig1t = .35031092712186400; %.39026571574305700
sig2c = sig1c;
sig2t = sig1t;
% sig3c = .56181805055156500;
% sig3t = .02333758968994630;
sig3c = sig1c; %will reduce to von misses if sig1t = sig1c
sig3t = sig1t;
tau23 = .07; %sheer strenth, tau23 is symetric with tau13
tau13 = tau23;
tau12 = .23;
% Ac = .636384473946997;
% At = .331316020473478;
% Bc = .210346685921127;
% Bt = 0.0628623668872776;
% Cc = Bc;
% Ct = Bt;
Ac = sig1c;
At = sig1c;
Bc = sig1c;
Bt = sig1c;
Cc = sig1c;
Ct = sig1c;
F1 = ((1/sig1t)-(1/sig1c));
F2 = ((1/sig2t)-(1/sig2c));
F3 = ((1/sig3t)-(1/sig3c));
F11 = (1/(sig1c*sig1t));
F22 = (1/(sig2c*sig2t));
F33 = (1/(sig3c*sig3t));
F44 = (1/(tau23^2));
F55 = (1/(tau13^2));
F66 = (1/(tau12^2));
F12 = -0.5*sqrt((F11*F22)); %only defines a range for F12, complete determination for orthotropic materials still needs to be resolved.
F13 = -0.5*sqrt((F11*F33));
F23 = -0.5*sqrt((F22*F33));
%F12 = -7.2806*10^(-4);
%F13 = 7.4203*10^(-4)
%F23 = F13;
% F12 = ((4/(At*Ac))-F11-F22-F66)/2;
%
% F13 = ((4/(Bt*Bc))-F11-F33-F55)/2;
%
% F23 = ((4/(Ct*Cc))-F33-F22-F44)/2;
syms sig1 sig2 sig3 G
[sig1,sig2,sig3] = meshgrid(linspace(-2,2,100));
sig1b = 0;
sig2b = 0;
sig3b = 0;
Data = sqrt(sig1.^2+sig2.^2+sig3.^2);
G = F1.*sig1 + F11.*sig1.^2 + F2.*sig2 + F22.*sig2.^2 + F3.*sig3 + F33.*sig3.^2 + (2*F12.*sig1.*sig2) + (2*F13.*sig1.*sig3) + (2*F23.*sig2.*sig3) - 1;
%G = F1.*sig1 + F11.*sig1.^2 + F2.*sig2 + F22.*sig2.^2 + F3.*sig3 + F33.*sig3.^2 + F44.*tau23.^2 + F55.*tau13.^2 + F66.*tau12.^2 + (2*F12.*sig1.*sig2) + (2*F13.*sig1.*sig3) + (2*F23.*sig2.*sig3) - 1;
G(G>1) = 1;
tiledlayout(1,2)
nexttile
Stich = patch(isosurface(sig1,sig2,sig3,G,0));
isonormals(sig1,sig2,sig3,G,Stich)
isocolors(sig1,sig2,sig3,Data,Stich)
colormap(hot(9))
shading interp
% Stich.FaceColor = 'interp';
% Stich.EdgeColor = 'black';
xlabel("\sigma_1 (GPa)");
ylabel("\sigma_2 (GPa)");
zlabel("\sigma_3 (GPa)");
title('Tsai-Wu Ultimate Yield Surface');
view(3);
axis padded
grid on
colorbar('Ticks',linspace(0,10,11),...
'TickLabels',["0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "10"]);
nexttile
H = squeeze(sum(G,3));
contourf(linspace(-2,2,100),linspace(-2,2,100),H);
axis equal
colorbar
xlabel("\sigma_1 (GPa)");
ylabel("\sigma_2 (GPa)");
title('Sum of sig3 data');
Here you can see how the numbers on the colorbar are still floating.
Thanks for the help,
Kevin
0 Kommentare
Akzeptierte Antwort
Simon Chan
am 16 Aug. 2021
Bearbeitet: Simon Chan
am 16 Aug. 2021
The limiting factor is the range of your data.
If you really want the colorbar starts from 0 to 10, you need to set the limit as well.
cb=colorbar('Ticks',linspace(0,10,11),...
'TickLabels',["0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "10"]);
cb.Limits=[1 10];
However, as your data are mostly below 4, the color of the colorbar doesn't change for values from 4 to 10
3 Kommentare
Simon Chan
am 16 Aug. 2021
That will be lots of work, please refer to the following as your reference:
cb=colorbar; % No need to set other values at this moment
number_of_level = 10; % Number of Ticks
cb_max = cb.Limits(2); % Get the max value
cb_min = cb.Limits(1); % Get the min value
cb_diff = cb_max - cb_min; % Calculate range of your data
cb_unit = cb_diff/(number_of_level-1); % Calculate each step
cb_pos = cb_min+cb_unit:cb_unit:cb_max-cb_unit; % Calculate Tick Positions
cb.Limits = [0 4]; % Now set the limit
cb_pos = [cb.Limits(1), cb_pos, cb.Limits(2)]; % Include the new end points
cb.Ticks = cb_pos; % Set the Ticks position
cb.TickLabels = string(arrayfun(@(x) sprintf('%.2f',x),cb_pos,'UniformOutput',false)); % Set the Ticks Label
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Axis Labels 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!