I can't get my color bar to be the range that I want it at.
Show older comments
I have the code show below and I am trying to get my colorbar so it shows ranges between 10^4 to 10^7 because that will make it easier to read. However, when It try to set the range to that using the clim operation it just shows me values from 1*10^6 to 10*10^6 making the graph look bad. can anyone help me?
A = 7.516*10^3; % These are placholders for the experiment done in the paper
B = -0.6738;
C = 5.339;
% A,B, and C are regression constants
% N is the life of the part.
BigA = [];
BigSigma=[];
BigN = [];
% When R = 0.1
W = logspace(4,7,4)
for N= [10^4,10^5,10^6,10^7]
K = A.*(N).^B + C;
sigma_max = (5.392*10^3).*N.^-0.1606 + 190.847;
R = 0.1;
A_0 = ((K/((1-R)*sigma_max))^2)*(1/pi); % This is really sqrt(A_0).
A_1 = logspace(0,4); % This is really sqrt(a)
sigma_w = (1-R).*sigma_max.*sqrt(A_0./((A_1/1000000) + A_0));
% sigma_w is the cyclic stress where defect size sqrt(A) wont propogate.
% sqrt(A_0) is the critical defect size below which a surface notch will
% not propogate at the endurance stress.
% sqrt(A) is the observed surface notch size.
BigA = [BigA;A_1];
BigSigma = [BigSigma;sigma_w];
BigN = [BigN;ones(1,length(A_1))*N];
end
contour(BigA,BigSigma,BigN,1000)
xlabel("Sqrt(A_0) (um)"), ylabel("Stress Range (MPA)")
xlim([10^0,10^4])
ylim([10^1,10^4])
grid on
clim([10^4 10^7])
colorbar
set(gca, 'XScale','log')
set(gca, 'YScale','log')
The graph ends up looking like this

Answers (2)
Walter Roberson
on 25 Mar 2025
On the scale of 10^4 to 10^7, 10^4 occupies 1/1000 of the range. Starting at 10^4 is a 1 to 2 pixel difference.
Notice the colorbar labels do not start at 0. That is because 0 is outside of clim.
Why doesn't the labeling start at 10^4 then? Because the labeling is automatic, and the automatic chooser chooses multiples of 10^6 and 10^4 is not a multiple of 10^6
If it really bugs you then
cb = colorbar;
cb.Ticks = [10^4, 10^6:10^6:10^7];
1 Comment
Sean Marcus
on 25 Mar 2025
If you are interested in using a logarithmic color scale, it might be something like this:
A = 7.516*10^3; % These are placholders for the experiment done in the paper
B = -0.6738;
C = 5.339;
% A,B, and C are regression constants
% N is the life of the part.
BigA = [];
BigSigma=[];
BigN = [];
% When R = 0.1
W = logspace(4,7,4);
for N= [10^4,10^5,10^6,10^7]
K = A.*(N).^B + C;
sigma_max = (5.392*10^3).*N.^-0.1606 + 190.847;
R = 0.1;
A_0 = ((K/((1-R)*sigma_max))^2)*(1/pi); % This is really sqrt(A_0).
A_1 = logspace(0,4); % This is really sqrt(a)
sigma_w = (1-R).*sigma_max.*sqrt(A_0./((A_1/1000000) + A_0));
% sigma_w is the cyclic stress where defect size sqrt(A) wont propogate.
% sqrt(A_0) is the critical defect size below which a surface notch will
% not propogate at the endurance stress.
% sqrt(A) is the observed surface notch size.
BigA = [BigA;A_1];
BigSigma = [BigSigma;sigma_w];
BigN = [BigN;ones(1,length(A_1))*N];
end
% contour(BigA,BigSigma,BigN,1000)
contour(BigA,BigSigma,log10(BigN),50)
xlabel("Sqrt(A_0) (um)"), ylabel("Stress Range (MPA)")
xlim([10^0,10^4])
ylim([10^1,10^4])
grid on
cl = [4 7];
clim(cl)
ticks = cl(1):cl(2);
colorbar('Ticks',ticks,'TickLabels',"10^"+ticks);
set(gca, 'XScale','log', 'YScale','log')
Categories
Find more on Discrete Data Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!