I can't get my color bar to be the range that I want it at.

조회 수: 7 (최근 30일)
Sean Marcus
Sean Marcus 2025년 3월 25일
답변: Voss 2025년 3월 25일
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

답변 (2개)

Walter Roberson
Walter Roberson 2025년 3월 25일
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
Sean Marcus
Sean Marcus 2025년 3월 25일
Sorry for bothing you but I tried using your code and i'm still getting the same graph. My problem with it right now is that you can't really tell the difference between the top like 75% of the graph making it not very readable. This is the bottom of my code that I tried to change with what you gave me.
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
cb = colorbar;
cb.Ticks = [10^4, 10^6:10^6:10^7];
set(gca, 'XScale','log')
set(gca, 'YScale','log')
hold on

댓글을 달려면 로그인하십시오.


Voss
Voss 2025년 3월 25일
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')

카테고리

Help CenterFile Exchange에서 Just for fun에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by