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 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