clc
clear
close all
x = 1:20;
hPlot = plot(x,sin(x));
set(gca,'xaxisLocation','top');
set(gca,'XTickLabel',[]); %// Clear current XTickLabel
ylim = get(gca,'YLim'); %// Get y limit of the plot to place your text annotations.
for k = 2:2:20
text(k,ylim(2)+0.1,num2str(k),'HorizontalAlignment','Center') %// Play with the 'ylim(1) -0.1' to place the label as you wish.
end
1 回答
这是使用文本注释的一个小解决方法 . 基本上,您清除当前的XTick标签并用类似的标签替换它们,但您可以指定与轴的距离:
给这个:
当然现在它被夸大了,你可以根据需要对y轴做同样的事情(使用当前轴的'XLim'属性,gca) .