필터 지우기
필터 지우기

Why do tick directions change when log scaling x-axis?

조회 수: 3 (최근 30일)
Dave Ortiz-Suslow
Dave Ortiz-Suslow 2018년 12월 18일
댓글: Dave Ortiz-Suslow 2019년 2월 7일
I just updated to Matlab 2018b (9.5.0.94444444) and I have come across a weird glitch when changing a plot axis scaling to logarithmic, from linear. I haven't come across this problem before in previous versions, but I haven't found a solution to this maddeningly simple problem. Here's an example that highlights the issue I see:
figure(1)
ha1 = subplot(2,1,1);
plot(1:10,linspace(1,100,10))
ha1.XDir = 'reverse';
title(ha1,'Linear axis scaling: no problem')
ha2 = subplot(2,1,2);
plot(1:10,linspace(1,100,10))
ha2.XDir = 'reverse';
ha2.XScale = 'log';
title(ha2,'X-axis log-scaled: tick direction problem')
Now with ha2, the x- and y-axes behave contrastly when setting:
ha2.TickDir = 'in';% or 'out'
Example
Changing TickDirMode to "manual" or "auto" has no affect.
Any help is appreciated. Thanks.
  댓글 수: 1
Dave Ortiz-Suslow
Dave Ortiz-Suslow 2018년 12월 18일
I wouldn't say the question is "answered", but the solution seems to be to download 2019a.

댓글을 달려면 로그인하십시오.

채택된 답변

Shawn Duenas
Shawn Duenas 2019년 2월 6일
편집: Shawn Duenas 2019년 2월 6일
Try this:
ha1.XDir = 'normal';
set(ha1,'view',[-180,-90])
I get that same issue:
Changing ytick direction is backwards. Check out the effect of this:
yax=get(gca,'yaxis');
set(yax,'tickdirection','in')
set(yax,'tickdirection','out')
I think it's because the plotting algorithm when xdir is reversed is stupid.
  댓글 수: 1
Dave Ortiz-Suslow
Dave Ortiz-Suslow 2019년 2월 7일
Changing the view is a quick and easy fix, but may not be general for all cases. Anyway, thanks for the contribution, the best solution will probably be to update versions.
FYI, the solution is fiddling with the view angle on a simple line plot to effectively reverse the axis direction.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Cris LaPierre
Cris LaPierre 2018년 12월 18일
I wonder if it is related to this question. There, it was a bug potentially related to having an exponent in the axis.
  댓글 수: 4
Cris LaPierre
Cris LaPierre 2018년 12월 18일
편집: Cris LaPierre 2018년 12월 18일
But the root cause is the same - reversing the direction of one of the axes. Don't do that, and your labels will appear normal.
Agreed - it shouldn't be there. But that's the nature of bugs. They are not there intentionally.
FWIW, I checked this in the 2019a prerelease software (might be able to see it here if you have access). This bug has been fixed.
Dave Ortiz-Suslow
Dave Ortiz-Suslow 2018년 12월 18일
편집: Dave Ortiz-Suslow 2018년 12월 18일
Cris: Thanks for checking it in 2019a, I'll see about getting the prerelease.

댓글을 달려면 로그인하십시오.


Dave Ortiz-Suslow
Dave Ortiz-Suslow 2018년 12월 18일
편집: Dave Ortiz-Suslow 2018년 12월 18일
A 50% answer to this question is to force the glitch on both the x- and y-axes. See code and figure below. The solution to the missplaced tick labels must be addressed following this question, which is not very satisfying. From Cris, maybe the best solution is to update to 2019 version.
figure(1)
ha1 = subplot(3,1,1);
plot(1:10,linspace(1,100,10))
ha1.XDir = 'reverse';
title(ha1,'Linear axis scaling: no problem')
ha2 = subplot(3,1,2);
plot(1:10,linspace(1,100,10))
ha2.XDir = 'reverse';
ha2.XScale = 'log';
title(ha2,'X-axis log-scaled: tick direction problem')
ha2.TickDir = 'in';% or 'out'
ha3 = subplot(3,1,3);
plot(1:10,linspace(1,100,10))
ha3.XScale = 'log';
ha3.XDir='reverse';ha3.YDir='reverse'
title(ha3,'X-axis log-scaled: tick direction wrong on both sides')
ha3.TickDir = 'out';

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by