Problem with xticklabel location when using 'YDir' reverse

조회 수: 4 (최근 30일)
Johann LAHAI
Johann LAHAI 2019년 11월 1일
댓글: Mohammad Sami 2019년 11월 3일
I'm trying to represent an audiogram, but the xticklabel is always set on the axis when I use 'Ydir','reverse' property.
PS : the property 'tickdir' doesn't change anything.
for misenforme=1:1
xaxistick=[250 500 750 1000 1500 2000 3000 4000 6000 8000];
xaxislabel=["250" "500" "" "1000" "" "2000" "" "4000" "" "8000"];
for f=1:length(Data.AudioT(1,:,1))-1;
audiogramme_moyen(1,f)=round(mean(Data.AudioT(:,f,1)),1);
audiogramme_moyen(2,f)=round(mean(Data.AudioT(:,f,2)),1);
audiogramme_moyen(3,f)=round(std(Data.AudioT(:,f,1)),1);
audiogramme_moyen(4,f)=round(std(Data.AudioT(:,f,2)),1);
end
semilogx(xaxistick,audiogramme_moyen(1,:),'-o','markeredgecolor','r','color','r'); hold on;
semilogx(xaxistick,audiogramme_moyen(2,:),'-x','markeredgecolor','b','color','b');
set(gca,'xtick',xaxistick,'xticklabels',xaxislabel,'xaxislocation','top','ydir','reverse','ytick',-10:10:120);
xlim([250 8000]); ylim([-10 120]); grid on;
end

답변 (1개)

Mohammad Sami
Mohammad Sami 2019년 11월 1일
You can try and change the position property of the xlabel.
a = gca;
pos = a.XLabel.Position;
pos(2) = pos(2) - 10; % adjust as desired.
a.XLabel.Position = pos;
  댓글 수: 2
Johann LAHAI
Johann LAHAI 2019년 11월 1일
Thank you for your answer. But it doesn't work. The property doesn't fit and it changes only the axis' title, not the xticklabel.
Mohammad Sami
Mohammad Sami 2019년 11월 3일
My mistake. I manage to recreate your issue.
It appears as soon as you set axis property XScale to log, the X tick labels somehow moves downwards as shown in your picture. If you set it to linear it will move back up. It seems that semilogx function will automatically set XScale to log.
The setting for TickDir 'in' seems to move the x tick labels to just above the grid line, while setting it to out, seems to move it just under the grid line.
If you want to use the scale, you might need to play around with the font size to make it look nice. Or you can adjust the x-axis limit to start from 0 instead of 250, to allow room for the label.
Alternatively instead of setting semilogx to plot the data, you can try plotting log(x) instead and set the tick labels as follows, using XScale as linear.
xaxistick= log([250 500 750 1000 1500 2000 3000 4000 6000 8000]);
xaxislabel=["250" "500" "" "1000" "" "2000" "" "4000" "" "8000"];
plot(xaxistick,audiogramme_moyen(1,:),'-o','markeredgecolor','r','color','r'); hold on;
plot(xaxistick,audiogramme_moyen(2,:),'-x','markeredgecolor','b','color','b');
set(gca,'xtick',xaxistick,'xticklabels',xaxislabel,'xaxislocation','top','ydir','reverse','ytick',-10:10:120);
xlim([250 8000]); ylim([-10 120]); grid on;

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

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by