我在 matlab 中绘制一些 3D 数据并尝试旋转 xlabel,使其与 xaxis 的方向相同。我将当前 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);
所以使用上面的代码,我在旋转之前将标签的位置设置在靠近相应轴中心的位置。如果标签只有一个字符,那么它可以工作。但是如果标签很长,那么它将使第一个字符与轴的中心对齐。原因是我没有考虑标签的长度。我知道我应该,但问题是我应该将标签从轴中心偏移多少?我只知道标签的字体大小和总字符数,如何知道标签的实际长度?谢谢。