How can I create a text box alongside my plot?

411 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2018 年 1 月 19 日
コメント済み: Ajay Kumar 2019 年 11 月 11 日
I have created a plot, and now I want to place a textbox on the side of it displaying values of some variables. How can I do that?

採用された回答

MathWorks Support Team
MathWorks Support Team 2018 年 1 月 19 日
One way to do this is to use "<https://www.mathworks.com/help/matlab/ref/annotation.html annotation>" command. The bare-bones syntax for this is as follows:
 
annotation('textbox', [0.5, 0.2, 0.1, 0.1], 'String', "hi")
This places a text box with horizontal offset of 50% of the Figure's width, and vertical offset of 20% of the Figure's height. The size of the box is 10% of Figure's height by 10% of Figure's width:
To place a textbox outside the plot, you can modify the position and/or dimensions of the axis. For example:
 
figure;
plot(1:10); % create a simple line plot
a = gca; % get the current axis;
% set the width of the axis (the third value in Position)
% to be 60% of the Figure's width
a.Position(3) = 0.6;
% put the textbox at 75% of the width and
% 10% of the height of the figure
annotation('textbox', [0.75, 0.1, 0.1, 0.1], 'String', "pi value is " + pi)
This will produce the following figure:
  1 件のコメント
Ajay Kumar
Ajay Kumar 2019 年 11 月 11 日
Can we do this using text ?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLabels and Annotations についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by