Why are Plot ticks increments inconsistently assigned?

2 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Grid Lines, Tick Values, and Labels 的更多信息

标签

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by