Reversing y axis direction causes xticks to invert and overlap with labels
조회 수: 19 (최근 30일)
이전 댓글 표시
I just switched from 2015a to 2018b and encounted a problem with the xticks and corresponding labels whenever I invert the y-axis. The Xtick direction seems reversed from the set value (in or out) and they overlap with the labels. I have no clue how to fix this.
Thanks!
subplot(1,3,1)
plot(rand(10,1),rand(10,1).*(1E-8))
subplot(1,3,2)
plot(rand(10,1),rand(10,1).*(1E-8))
set(gca,'Ydir','reverse')
subplot(1,3,3)
plot(rand(10,1),rand(10,1).*(1E-8))
set(gca,'Ydir','reverse')
set(gca,'TickDir','out')
댓글 수: 4
채택된 답변
Samuel Coakley
2019년 5월 31일
편집: Samuel Coakley
2019년 5월 31일
So I ran into the same problem and my solution is below.
Say you are plotting some data in A. Instead of plotting just A, plot -A and change the y tick labels. This means you don't have to reverse the axis so the x tick labels are still in the right place.
plot(1:length(A), -A)
yt = get(gca,'YTickLabel');
for ii=1:length(yt)
ytt{ii} = yt{ii}(2:end); % This trims the minus sign from the negative numbers
end
set(gca, 'YTickLabel', ytt)
추가 답변 (2개)
Stefanie Schwarz
2021년 3월 22일
편집: Stefanie Schwarz
2021년 3월 22일
This is a bug in R2018b that was fixed in R2019a. See the following Bug Report:
A workaround is to set the Y-axis label to text and insert spaces.
Example:
>> set(gca, 'YTickLabel', {'0 ', '1 ', '2 ', '3 ', '4 '})
댓글 수: 0
Robert Weigel
2021년 5월 13일
Adding an empty subscript worked for the case when the x-tick labels have exponents.
xtl = get(gca,'XTickLabel'); % {'10^{1}', '10^{2}'}
for i = 1:length(xtl)
xtl{i} = [xtl{i},'_{ }']; % Append empty subscript
end
set(gca,'XTickLabel',xtl);
댓글 수: 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!