问题描述
如果要使用与绘制text1相同的位置,则需要在水平文本(text 1)旁边绘制垂直文本(text 2)。
我尝试根据text1的Extent属性推断出第二个位置,但我无法正确获得单位:
rec = txt.Extent;
pos_x = rec(1) + rec(3);
pos_y = rec(2);
text(pos_x,pos_y,txt2,'HorizontalAlignment','center','FontSize',sz,'Rotation',90,'Units','normalized');
我也尝试过以像素为单位,但这也不起作用。
在文档中,我似乎将范围值标准化了,但我不知道是否需要其他任何方法来显示这些坐标上的第二个位置。
解决方法
这看起来像您想要的吗 plot with rotated text
以下是绘制以上情节的代码
plot(1:1.2)
h1 = text(1,1,'Text String 1','verticalalignment','bottom');
rec = h1.Extent;
pos_x = rec(1) + rec(3);
pos_y = rec(2) + rec(4);
text(pos_x,pos_y,'Text String 2','HorizontalAlignment','left','FontSize',10,'Rotation',90,'bottom');