gpt4 book ai didi

matlab - 使用 `text` 绘图时如何包装字符串?

转载 作者:太空宇宙 更新时间:2023-11-03 20:23:29 25 4
gpt4 key购买 nike

我有一个很长的字符串,我想将其作为描述性文本添加到子图中。

description = 'This kitchen has white cabinets and two blue chairs. The upper cabinet has a black microwave. The paper towels are above the trash can. There is a black garbage can just on the left of the blue chair. On its left there is a red fire distinguisher.';

我尝试在每个句子后添加换行符以使其更合适。

subplot(1,2,2);
with_new_lines = regexprep(description, '\.', '\.\n');
text( 0.5, 0.5, with_new_lines, 'FontSize', 14', 'FontWeight', 'Bold', ...
'HorizontalAlignment', 'Center', 'VerticalAlignment', 'middle' ) ;

但它仍然不能正确地适合轴。

有没有办法动态包装字符串以适合子图?

enter image description here

最佳答案

在关闭 FitBoxToText 属性的情况下使用注释框怎么样?

description = 'This kitchen has white cabinets and two blue chairs. The upper cabinet has a black microwave. The paper towels are above the trash can. There is a black garbage can just on the left of the blue chair. On its left there is a red fire distinguisher.';
figure;subH=subplot(1,2,2);
pos=get(subH,'Position');
annotation('textbox', pos,...
'String', description,...
'FitBoxToText','off');

您可以通过更改 pos 的前两个元素来更改位置,这(我认为)描述了左下角,但忘记了。

关于matlab - 使用 `text` 绘图时如何包装字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42258649/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com