I want to design a function, which can add text in the right corner of the figure according to user's input parameter ('UpperLeft', 'UpperRight', 'LowerLeft', 'LowerRight'). I implement it in the following way: If I want to add text in the upper left corner, I firstly get the min x and max y of the axis in the figure, then use text(min_x, max_y, 'text')
to draw it . But I don't know what function can get the min x and max y. And if there any other way to implement the function I want?
Solution added later
I have found the solution, just use text()
. For example, if I want to and text at the upper left corner of the figure, I just use the code below
text([x], [y], [text], 'HorizontalAlignment', 'left', 'VerticalAlignment', 'upper')
CodePudding user response:
x = 3*sin(linspace(0,10,100));
figure
plot(x)
xl = xlim
yl = ylim
% upper left (ish), you'll want to position the text a little down and to
% the right depending on the dimensions of the plot
text(xl(1), yl(2), 'text')