在 matlab 中删除 semilogx plot x-axis 中的小刻度

Removing minor ticks in x-axis of semilogx plot in matlab

这是代码示例

x = 0:1000;
y = log(x);
semilogx(x,y)

我想删除 x-axis 上 10^0 和 10^1 之间的小刻度线。

我试过了:

set(gca,'XminorTick','off')

但是没用

出于充分的理由,确实没有好的方法。最好明确说明绘图使用的是对数刻度。

如果您确实需要,最简单的方法是对您的数据执行对数转换并按规则的线性比例绘制它。然后指定自定义刻度标签,使其显示为对数刻度。

%// Plot after performing log transform of your xdata
plot(log10(x), y)

%// Tick locations
ticks = 0:3;

%// Create custom tick labels
labels = arrayfun(@(x)sprintf('10^%d', x), ticks, 'uni', 0);

%// Update the ticks and ticklabels
set(gca, 'xtick', ticks, 'XTickLabels', labels)

mo必须大写

set(gca,'XMinorTick','Off')

这在 semilogx 图中对我有用。