用彩色文本在图外添加描述 [英] Adding description outside the plot with coloured text

查看:84
本文介绍了用彩色文本在图外添加描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working on a visualisation of my data and would like to add a description of a plot. The description will be added outside the plot. For that I have written:

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

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

But it doesn't work, I get the error:

Text类上没有location属性.

There is no location property on the Text class.

我该如何解决?

这是我想要的输出:

推荐答案

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

The location input pair you're giving to text are for the legend, not text objects...

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

The location is specified by the first two inputs (x/y), so if you don't use the location input you get this:

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

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

If you want the text location to be independent of the axes, you should use an annotation instead, which gets its location from the figure rather than the axes.

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

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

Because I used normalized position here, the Position argument is a percentage of the figure window. To get the behaviour I suspect you're after, you'll have to reposition the axes too...

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

这篇关于用彩色文本在图外添加描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆