首页 文章

MATLAB图中轴号与轴之间的距离

提问于
浏览
2

我对y轴和x轴重叠的轴数进行了一点点挣扎,就像它在图像中所示 . 我想保持数字的大小,因此认为简单地将数字从轴本身移开将是处理这个问题的适当方法 .

是否有可能这样做

提前谢谢,乔

1 回答

  • 1

    这是使用文本注释的一个小解决方法 . 基本上,您清除当前的XTick标签并用类似的标签替换它们,但您可以指定与轴的距离:

    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
    

    给这个:

    enter image description here

    当然现在它被夸大了,你可以根据需要对y轴做同样的事情(使用当前轴的'XLim'属性,gca) .

相关问题