Why are Plot ticks increments inconsistently assigned?

1 回表示 (過去 30 日間)
Glenn Kubota
Glenn Kubota 2022 年 10 月 18 日
回答済み: Sanjana 2023 年 6 月 8 日
When I create a simple x-y plot, I would expect that the ticks woiuld increase in size as the samples in my data would increase. And that seems to be mostly the case. If I do a plot([0,1], [0, 1.8]), then my y-axis has ticks spaced 0.2 apart. If I do a plot([0,1], [0, 2.1]), then my y-axis has ticks spaced 0.5 apart. However, the max value is between 1.4 and 1.5, the tick spacing is 0.5 instead of 0.2, so there are not many ticks shown on the plot. I created a script to show how the tick increment is inconsistent.
Is this a bug, or is there some reason for this?
lim = logspace(log10(1), log10(10), 200)';
tick = zeros(length(lim), 1);
for n=1:length(lim)
p=plot([0,1], [0, lim(n)]); % create a simple plot with two points
tick(n) = p.Parent.YTick(2); % save the tick size
end
p=loglog(lim, tick);
xlabel('Max plot line value');
ylabel('Tick increment');
grid on
p.Parent.XTick = [1;1.4;1.5;2;5;10];
p.Parent.XTickLabel = arrayfun(@num2str, p.Parent.XTick, 'UniformOutput', false);
p.Parent.YTick = [0.1;0.2;0.5;1];
p.Parent.YTickLabel = arrayfun(@num2str, p.Parent.YTick, 'UniformOutput', false);

回答 (1 件)

Sanjana
Sanjana 2023 年 6 月 8 日
Hi Glenn,
As per the official documentation, there is no default spacing for ticks, but you can specify the spacing as per requirement using “xticks” and “yticks” properties of “Axes” in MATLAB.
These properties allow you to explicitly declare the location of the ticks along the respective axis.
Please refer to the following links, for further information,
Hope this helps!

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by