loglog plot, change yticks to non 10^ values. IS there a straight forward way like for xticks
조회 수: 14 (최근 30일)
이전 댓글 표시
Hi there
Is there an straight forward way to have the yticks on the loglog plot in terms of 100 instead of 10^2?
I have got it to work, from seeing answers to previous questions posed to the community, but I'm confused as to why the yticks are so much more intricate than the xtick.
Thanks as always
Gerard
z = [2 4 6 10 15 20 30];
q = 2:2000;
V_h = zeros(length(z), length(q));
for ii =1:length(z)
V_h(ii,:) = (q*3.6)/(4*z(ii));
end
loglog(q,V_h)
grid
xlim([2 2000])
ylim([0.1 1000])
% Option 1
% Works for xtick, not ytick
set(gca, 'XTick', [0.1 1 10 100 1000 2000])
set(gca, 'YTick', [0.1 1 10 100 1000])
% Option 2
% Works for both xtick and ytick
set(gca, 'XTick', [0.1 1 10 100 1000 2000])
yticks = get(gca,'YTick');
set(gca,'YTickLabel',yticks);
% Option 3
% Works for both xtick and ytick
xticks([0.1 1 10 100 1000 2000])
yticks = get(gca,'YTick');
set(gca,'YTickLabel',yticks);
% Option 4
% Works only for xtick, not ytick
% xticks([0.1 1 10 100 1000 2000])
% yticks([0.1 1 10 100 1000])
댓글 수: 0
채택된 답변
Dyuman Joshi
2023년 8월 24일
편집: Dyuman Joshi
2023년 8월 24일
"... but I'm confused as to why the yticks are so much more intricate than the xtick."
I suspect it is becase the values to x-ticks are not incrementally ordered on the log scale whereas the values to y-ticks are; if tick values to loglog plot are incrementally ordered, then the tick labels will be displayed in exponential format.
(I have not found any such information in the documentation yet, for reference, this is just what I think how it works currently. I'll attach a reference if and when I find it)
That's why the methods that work change the ticklabels to display the values in the default (for the lack of a better term) format.
Let's add a value to make the y-ticks exponentially non-linear and see the output -
z = [2 4 6 10 15 20 30];
q = 2:2000;
V_h = zeros(length(z), length(q));
for ii =1:length(z)
V_h(ii,:) = (q*3.6)/(4*z(ii));
end
loglog(q,V_h)
grid
xlim([2 2000])
ylim([0.1 1000])
set(gca, 'XTick', [0.1 1 10 100 1000 2000])
%Intermediate value added to y-ticks i.e. 500
set(gca, 'YTick', [0.1 1 10 100 500 1000])
As you can see, the y-ticks are now displayed in the default format.
Edit - Changing the exponent value of tick labels will not work in this case - "If the axis has a log scale, then the Exponent property has no effect."
댓글 수: 2
Dyuman Joshi
2023년 8월 25일
"... it does seem to be a functionality, that I ddint expect to be different ... "
Neither did I, but it seems the working of ticklabels is different when an axis has a log scale.
Feels like an anamoly. And we don't know why is that.
I'll report this to TMW.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Axis Labels에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!