Adding description outside the plot with coloured text

泄露秘密 提交于 2020-01-24 19:30:09

问题


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:

There is no location property on the Text class.

How can I fix this?

This is my desired output:


回答1:


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

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 )

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] )

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] )




回答2:


text() is the wy to go if you want an arbitrary description somewhere on your figure, but if your just want to place the legend outside, use the location Name-Value-pair in legend(...,'Location,'northeastoutside'). The example puts the legend on the top right next to your figure.



来源:https://stackoverflow.com/questions/59681725/adding-description-outside-the-plot-with-coloured-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!