在 Matlab 中剪切多行标题
Multiple lines title cut in Matlab
我正在使用元胞数组来显示多行标题。它有时不能很好地工作并且不明白为什么。我正在使用 subplot
来定义我的坐标轴;
这是我的代码。前两个子图效果很好,但第三个标题被删掉了,它只显示最后两项( C 和 D 字符串)。
hf = figure;
subplot( 2, 2, 1 );
title({'test1', 'test2','test3', 'test4'});
subplot( 2, 2, 3 );
title({'testA', 'testB','testC', 'testD'});
subplot( 1, 2, 2 );
title({'A', 'B','C', 'D'});
我是不是做错了什么?
作为解决方法,我建议您执行以下操作:
sp3 = subplot(1,2,2);
title({'A', 'B','C', 'D'});
drawnow % force calculating the position *after* inserting the title
ph = sp3.Position; % get the desired position
sp3.delete % remove the axes
subplot( 2, 2, 1 );
title({'test1', 'test2','test3', 'test4'});
subplot( 2, 2, 3 );
title({'testA', 'testB','testC', 'testD'});
sp3 = subplot(1,2,2);
title({'A', 'B','C', 'D'});
sp3.Position = ph; % set the axes to the right hight
这个想法很简单:
- 将坐标轴单独放置在图中,以便正确调整大小
- 获取他们的位置值
- 删除它们 - 这样它们就不会干扰其他轴
- 再次放置所有轴
- 将所有裁剪轴的位置设置为正确的值。
诀窍是使用drawnow
,所以Matlab实际上是在你得到位置之前把坐标轴的所有部分都放好,否则会出错。
我正在使用元胞数组来显示多行标题。它有时不能很好地工作并且不明白为什么。我正在使用 subplot
来定义我的坐标轴;
这是我的代码。前两个子图效果很好,但第三个标题被删掉了,它只显示最后两项( C 和 D 字符串)。
hf = figure;
subplot( 2, 2, 1 );
title({'test1', 'test2','test3', 'test4'});
subplot( 2, 2, 3 );
title({'testA', 'testB','testC', 'testD'});
subplot( 1, 2, 2 );
title({'A', 'B','C', 'D'});
我是不是做错了什么?
作为解决方法,我建议您执行以下操作:
sp3 = subplot(1,2,2);
title({'A', 'B','C', 'D'});
drawnow % force calculating the position *after* inserting the title
ph = sp3.Position; % get the desired position
sp3.delete % remove the axes
subplot( 2, 2, 1 );
title({'test1', 'test2','test3', 'test4'});
subplot( 2, 2, 3 );
title({'testA', 'testB','testC', 'testD'});
sp3 = subplot(1,2,2);
title({'A', 'B','C', 'D'});
sp3.Position = ph; % set the axes to the right hight
这个想法很简单:
- 将坐标轴单独放置在图中,以便正确调整大小
- 获取他们的位置值
- 删除它们 - 这样它们就不会干扰其他轴
- 再次放置所有轴
- 将所有裁剪轴的位置设置为正确的值。
诀窍是使用drawnow
,所以Matlab实际上是在你得到位置之前把坐标轴的所有部分都放好,否则会出错。