Distance between axis label and axis in MATLAB figure

后端 未结 3 1100
后悔当初
后悔当初 2021-02-03 09:54

I\'m plotting some data with MATLAB and I\'d like to adjust the distance between axis label and the axis itself. However, simply adding a bit to the \"Position\" property of the

3条回答
  •  Happy的楠姐
    2021-02-03 10:37

    You can accomplish this by adjusting the position of the axis an xlabel. I also suggest using "normalized" units so your positioning does not depend on the data range. Here's an example:

    figure
    plot(rand(1,10))
    
    set(gca, 'Units', 'Normalized');
    pos = get(gca, 'Position');
    offset = 0.1;
    set(gca, ...
        'Box'         , 'off'                        , ...
        'LooseInset'  , get(gca, 'TightInset') * 1.5 , ...
        'TickDir'     , 'in'                         , ...
        'XMinorTick'  , 'off'                        , ...
        'YMinorTick'  , 'off'                        , ...
        'TickLength'  , [.02 .02]                    , ...
        'LineWidth'   , 1                            , ...
        'XGrid'       , 'off'                        , ...
        'YGrid'       , 'off'                        , ...
        'FontSize'    , 18                           , ...
        'Position'    , pos + [0, offset, 0, -offset]);
    
    h = xlabel('Time (s)');
    set(h, 'Units', 'Normalized');
    pos = get(h, 'Position');
    set(h, 'Position', pos + [0, -offset, 0]);
    

提交回复
热议问题