Make Equal tick spacing in a loglog plot

조회 수: 35 (최근 30일)
Thor Edvard Kristensen
Thor Edvard Kristensen 2021년 12월 30일
편집: Dave B 2021년 12월 30일
Hello,
Can any of you help me with making a equal spacing of in a loglog plot. You can see on the picture below that the interval between the ticks is becoming smaller and smaller.
Is it possible to make the y-axis look the this picture with equal spacing?
Thank you

채택된 답변

Dave B
Dave B 2021년 12월 30일
If you want n logarithmically spaced ticks (which would appear linearly spaced on a log plot, you should just set the ticks to be logarithmically spaced. That's pretty easy with logspace:
loglog([1 100],[1 100])
nticks = 4;
yticks(logspace(0,2,nticks))
% note that this is equivalent to yticks(10.^linspace(0,2,4))
grid on
set(gca,'YMinorGrid', 'off', 'YMinorTick', 'off')
The minor ticks are a bit trickier, you can get at them by grabbing the YAxis object
figure
loglog([1 100],[1 100])
nticks = 4;
yticks(logspace(0,2,nticks))
nminorticks = 16;
ax=get(gca,'YAxis');
ax.MinorTickValues=logspace(0,2,nminorticks);
grid on
  댓글 수: 2
Thor Edvard Kristensen
Thor Edvard Kristensen 2021년 12월 30일
Is it possible to make it look like this? the first picture i showed?
Dave B
Dave B 2021년 12월 30일
편집: Dave B 2021년 12월 30일
Yeah just set your ticks to the values you want - this image just shows two ticks on the x axis and two ticks on the y axis. If you want to explicitly set the tick labels to read some specific values, that's easy enough too (the 'tickformat' properties/functions don't seem to work in log plots)
loglog([1e4 5e6],[1000 100],'k')
hold on
loglog([1e4 5e6],[1000 100]*1.2,'k--')
axis tight
xticks([1e4 1e6])
yticks([100 1000])
xticklabels(["1.00E+04" "1.00E+06"])
yticklabels(["100" "1 000"])
xlabel('Life (cycles)')
ylabel({'Stress' 'range' '(MPa)'},'Rotation',0)
set(gca,'XMinorTick','off','YMinorTick','off','TickDir','out')
title('Quantile curves')
legend('1%','2%','Location','NorthEastOutside','Box','off')
box off

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

추가 답변 (1개)

the cyclist
the cyclist 2021년 12월 30일
편집: the cyclist 2021년 12월 30일
I am not certain that I understand what you mean, but maybe you want the semilogx function rather than loglog?

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by