java公路中轴_MATLAB图中轴标签与轴之间的距离

我写了一个应该完全符合你想要的功能 . 它使轴保持完全相同的大小和位置,向下移动x标签并将图形尺寸增大到足以显示标签:

function moveLabel(ax,offset,hFig,hAxes)

% get figure position

posFig = get(hFig,'Position');

% get axes position in pixels

set(hAxes,'Units','pixels')

posAx = get(hAxes,'Position');

% get label position in pixels

if ax=='x'

set(get(hAxes,'XLabel'),'Units','pixels')

posLabel = get(get(hAxes,'XLabel'),'Position');

else

set(get(hAxes,'YLabel'),'Units','pixels')

posLabel = get(get(hAxes,'YLabel'),'Position');

end

% resize figure

if ax=='x'

posFigNew = posFig + [0 -offset 0 offset];

else

posFigNew = posFig + [-offset 0 offset 0];

end

set(hFig,'Position',posFigNew)

% move axes

if ax=='x'

set(hAxes,'Position',posAx+[0 offset 0 0])

else

set(hAxes,'Position',posAx+[offset 0 0 0])

end

% move label

if ax=='x'

set(get(hAxes,'XLabel'),'Position',posLabel+[0 -offset 0])

else

set(get(hAxes,'YLabel'),'Position',posLabel+[-offset 0 0])

end

% set units back to 'normalized' and 'data'

set(hAxes,'Units','normalized')

if ax=='x'

set(get(hAxes,'XLabel'),'Units','data')

else

set(get(hAxes,'YLabel'),'Units','data')

end

end

在这种情况下, offset 应该是像素的绝对偏移量 . 如果你想要相对偏移,我认为这个函数很容易被重写 . hFig 是图形句柄, hAxes 轴处理 .

编辑:在调用函数之前,使用 hFig = figure; 创建图形,使用 hAxes = axes; 创建图形(然后像在问题中一样设置轴: set(hAxes,...) ) .

EDIT2:添加 hAxes 和 XLabel 的 'Units' 分别变回'normalized'和'data'的行 . 这样,在调整大小后,这个数字会保持你想要的方式 .

EDIT3:修改了该功能,适用于X和Y标签 . 附加输入 ax 应为 'x' 或 'y' .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值