在图外添加带有彩色文本的描述

问题描述 投票:0回答:1

我正在对我的数据进行可视化,并希望添加对图形的描述。说明将添加到图的外部。为此,我写了:

plot(1:10)
text(2,8,'my text here ','Color','green','FontSize',14,'location','EastOutside')

但是它不起作用,我得到了错误:

[Text类上没有location属性。

我该如何解决?

这是我想要的输出:

“

matlab plot label matlab-figure
1个回答
0
投票

您提供给locationtext输入对是用于legend,而不是text对象...

位置由前两个输入(x / y)指定,因此,如果不使用location输入,则会得到以下信息:

text( 2, 8, 'my text here ', 'Color', 'green', 'FontSize', 14 )

plot with text

如果要使文本位置独立于轴,则应改用annotation,它从而不是获取其位置。

annotation( 'textbox', 'String', 'my annotation', 'Color', 'green', ...
            'FontSize', 14, 'Units', 'normalized', 'EdgeColor', 'none', ...
            'Position', [0.8,0.5,0.2,0] )

因为在这里使用normalized位置,所以Position参数是图形窗口的百分比。要获得我怀疑您要执行的操作,还必须重新定位轴...

set( gca, 'Position', [0.1, 0.1, 0.6, 0.8] )

plot with annotation

© www.soinside.com 2019 - 2024. All rights reserved.