Problem with xticklabel location when using 'YDir' reverse
4 views (last 30 days)
Show older comments
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

Answers (1)
Mohammad Sami
on 1 Nov 2019
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 Comments
Mohammad Sami
on 3 Nov 2019
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;
See Also
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!