我正在matlab中绘制一些3D数据并尝试旋转xlabel,使其定向与x轴相同的方向 . 我将当前3D图形的视图固定到某个角度,并且使用轨迹和错误我找到了旋转标签的正确角度 .

view(al, ae);  % where al and ae is the parameter for the view I want
theta = 52;    % this angle is obtained by trail and error
xlabel('label at some angle', 'rot', theta)

现在标签朝向正确的方向,但我发现它不再停留在相应轴的中心,即标签的中心不再与x轴的中心对齐 . 这有什么办法让他们再次对齐吗?

实际上,我尝试类似enter link description here的东西,但它对视图效果不佳 . 按照该链接中的想法,我尝试类似的东西

xf = 1.2*min(get(gca, 'xlim'));   % in my case zero is the middle or the xlim
yf = 1.2*min(get(gca, 'ylim'));   % in my case zero is the middle or the ylim
set(get(gca,'XLabel'),'Position', [0, yf, zf]);
set(get(gca,'YLabel'),'Position', [xf, 0, zf]);
set(get(gca,'xlabel'),'rot',thetax);
set(get(gca,'ylabel'),'rot',thetay);
set(get(gca,'zlabel'),'rot',thetaz);

因此,通过上面的代码,我可以在旋转之前将标签的位置设置为靠近相应轴中心的位置 . 如果标签只有一个字符,那么它可以工作 . 但是如果标签很长,那么它将使第一个字符与轴的中心对齐 . 原因是我没有考虑标签的长度 . 我知道我应该,但问题是我应该从轴的中心偏移标签多少?我只知道字体的大小和标签的总字符数,我如何找出标签的实际长度?谢谢 .