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!