loglog plot, change yticks to non 10^ values. IS there a straight forward way like for xticks
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Gerard Nagle
am 24 Aug. 2023
Kommentiert: Dyuman Joshi
am 25 Aug. 2023
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 Kommentare
Akzeptierte Antwort
Dyuman Joshi
am 24 Aug. 2023
Bearbeitet: Dyuman Joshi
am 24 Aug. 2023
"... 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 Kommentare
Dyuman Joshi
am 25 Aug. 2023
"... 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Axis Labels finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!